Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void registerCommands() {
@Override
public void registerListeners() {
super.registerListeners(
new GeneratorListener()
new GeneratorListener()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import net.buildtheearth.buildteamtools.modules.generator.model.History;
import net.buildtheearth.buildteamtools.modules.network.model.Permissions;
import net.buildtheearth.buildteamtools.utils.Utils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -16,54 +14,43 @@

public class GeneratorCommand implements CommandExecutor {


public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String cmdLabel, String @NotNull [] args) {
if (!(sender instanceof Player p)) {
sender.sendMessage("§cOnly players can execute this command.");
return true;
}

if(!p.hasPermission(Permissions.GENERATOR_USE)) {
if (!p.hasPermission(Permissions.GENERATOR_USE)) {
p.sendMessage(ChatHelper.getErrorString("You don't have permission to use this command!"));
return true;
}

// Command Usage: /gen
if (args.length == 0) {
new GeneratorMenu(p, true);
return true;
}


// Command Usage: /gen house ...
switch (args[0]) {
switch (args[0].toLowerCase()) {
case "house":
GeneratorModule.getInstance().getHouse().analyzeCommand(p, args);
return true;

// Command Usage: /gen road ...
case "road":
GeneratorModule.getInstance().getRoad().analyzeCommand(p, args);
return true;

// Command Usage: /gen rail ...
case "rail":
p.sendMessage(Component.text("This generator have some serious issues and is currently disabled.", NamedTextColor.DARK_RED));
//GeneratorModule.getInstance().getRail().analyzeCommand(p, args);
GeneratorModule.getInstance().getRail().analyzeCommand(p, args);
return true;

// Command Usage: /gen tree ...
case "tree":
GeneratorModule.getInstance().getTree().analyzeCommand(p, args);
return true;

// Command Usage: /gen field ...
case "field":
p.sendMessage(Component.text("This generator have some serious issues and is currently disabled.", NamedTextColor.DARK_RED));
//GeneratorModule.getInstance().getField().analyzeCommand(p, args);
p.sendMessage("§cThis generator has serious issues and is currently disabled.");
return true;

// Command Usage: /gen history
case "history":
if (GeneratorModule.getInstance().getPlayerHistory(p).getHistoryEntries().isEmpty()) {
p.sendMessage("§cYou didn't generate any structures yet. Use /gen to create one.");
Expand All @@ -85,6 +72,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
case "redo":
GeneratorModule.getInstance().getPlayerHistory(p).redoCommand(p);
return true;

default:
sendHelp(p);
return true;
Expand All @@ -93,7 +81,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N

public static void sendHelp(CommandSender sender) {
ChatHelper.sendMessageBox(sender, "Generator Command", () -> {

sender.sendMessage("§eHouse Generator:§7 /gen house help");
sender.sendMessage("§eRoad Generator:§7 /gen road help");
sender.sendMessage("§eRail Generator:§7 /gen rail help");
Expand All @@ -103,7 +90,6 @@ public static void sendHelp(CommandSender sender) {
sender.sendMessage("§eGenerator History:§7 /gen history");
sender.sendMessage("§eUndo last command:§7 /gen undo");
sender.sendMessage("§eRedo last command:§7 /gen redo");

});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public boolean checkForPlayer(Player p) {
if (GeneratorUtils.checkForNoWorldEditSelection(p))
return false;

if (getPlayerSettings().get(p.getUniqueId()).getBlocks() == null) // Needed because block checks are made afterwards
if (getPlayerSettings().get(p.getUniqueId()).getBlocks() == null)
getPlayerSettings().get(p.getUniqueId()).setBlocks(GeneratorUtils.analyzeRegion(p, p.getWorld()));

Block[][][] blocks = getPlayerSettings().get(p.getUniqueId()).getBlocks();
Expand All @@ -35,4 +35,4 @@ public void generate(Player p) {

new HouseScripts(p, this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,150 @@
import net.buildtheearth.buildteamtools.modules.generator.GeneratorModule;
import net.buildtheearth.buildteamtools.modules.generator.model.GeneratorComponent;
import net.buildtheearth.buildteamtools.modules.generator.model.GeneratorType;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.List;

public class Rail extends GeneratorComponent {

private static final int TARGET_BLOCK_RANGE = 200;

public Rail() {
super(GeneratorType.RAILWAY);
}

@Override
public boolean checkForPlayer(Player p) {
return !GeneratorUtils.checkForNoWorldEditSelection(p);
public void analyzeCommand(Player player, String[] args) {
addPlayerSetting(player);

if (args.length >= 2) {
String subCommand = args[1].toLowerCase();

switch (subCommand) {
case "help", "info", "?" -> {
sendHelp(player);
return;
}

case "add", "point" -> {
addPoint(player);
return;
}

case "clear", "reset" -> {
clearPoints(player);
return;
}

case "points", "list" -> {
listPoints(player);
return;
}

default -> {
player.sendMessage("§cUnknown rail command: §7" + args[1]);
sendHelp(player);
return;
}
}
}

generate(player);
}

@Override
public boolean checkForPlayer(Player player) {
RailSettings settings = getRailSettings(player);

if (settings != null && settings.hasEnoughCustomControlPoints())
return true;

return !GeneratorUtils.checkForNoWorldEditSelection(player);
}

@Override
public void generate(Player p) {
if (!GeneratorModule.getInstance().getRail().checkForPlayer(p))
public void generate(Player player) {
if (!GeneratorModule.getInstance().getRail().checkForPlayer(player))
return;

RailSettings settings = getRailSettings(player);

if (settings != null && settings.hasEnoughCustomControlPoints()) {
new RailScripts(player, this, new ArrayList<>(settings.getCustomControlPoints()));
return;
}

new RailScripts(player, this);
}

private void addPoint(Player player) {
RailSettings settings = getRailSettings(player);

if (settings == null) {
player.sendMessage("§cRail settings could not be loaded.");
return;
}

Block targetBlock = player.getTargetBlockExact(TARGET_BLOCK_RANGE);

if (targetBlock == null) {
player.sendMessage("§cLook at a block first to add a rail point.");
return;
}

Vector point = new Vector(
targetBlock.getX(),
targetBlock.getY() + 1,
targetBlock.getZ()
);

settings.addCustomControlPoint(point);

player.sendMessage("§aAdded rail point §7#" + settings.getCustomControlPoints().size()
+ " §8(" + point.getBlockX() + ", " + point.getBlockY() + ", " + point.getBlockZ() + ")");
}

private void clearPoints(Player player) {
RailSettings settings = getRailSettings(player);

if (settings == null) {
player.sendMessage("§cRail settings could not be loaded.");
return;
}

settings.clearCustomControlPoints();
player.sendMessage("§aCleared all custom rail points.");
}

private void listPoints(Player player) {
RailSettings settings = getRailSettings(player);

if (settings == null) {
player.sendMessage("§cRail settings could not be loaded.");
return;
}

List<Vector> points = settings.getCustomControlPoints();

if (points.isEmpty()) {
player.sendMessage("§eNo custom rail points saved.");
return;
}

player.sendMessage("§aSaved rail points:");

for (int index = 0; index < points.size(); index++) {
Vector point = points.get(index);

player.sendMessage("§7#" + (index + 1)
+ " §8(" + point.getBlockX() + ", " + point.getBlockY() + ", " + point.getBlockZ() + ")");
}
}

new RailScripts(p, this);
private RailSettings getRailSettings(Player player) {
return (RailSettings) getPlayerSettings().get(player.getUniqueId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,19 @@
import net.buildtheearth.buildteamtools.modules.generator.model.FlagType;

public enum RailFlag implements Flag {
LANE_COUNT("c", FlagType.INTEGER);

private final String flag;
private final FlagType flagType;

RailFlag(String flag, FlagType flagType){
this.flag = flag;
this.flagType = flagType;
}
;

@Override
public String getFlag() {
return flag;
return null;
}

@Override
public FlagType getFlagType() {
return flagType;
return null;
}

public static RailFlag byString(String flag){
for(RailFlag railFlag : RailFlag.values())
if(railFlag.getFlag().equalsIgnoreCase(flag))
return railFlag;

public static RailFlag byString(String flag) {
return null;
}
}
}
Loading
Loading