Major rewrite of command system, msg sending fixes
This commit is contained in:
parent
7d87744c36
commit
8171b32a97
25
pom.xml
25
pom.xml
@ -12,10 +12,18 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>minecraft-libraries</id>
|
||||
<name>Minecraft Libraries</name>
|
||||
<url>https://libraries.minecraft.net</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@ -44,6 +52,11 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/deps/datafixerupper.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>brigadier</artifactId>
|
||||
<version>1.0.18</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -87,5 +100,13 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<includes>
|
||||
<include>**/*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
||||
|
72
src/default-favourites.yml
Normal file
72
src/default-favourites.yml
Normal file
@ -0,0 +1,72 @@
|
||||
'26':
|
||||
deal: 5
|
||||
section: 4
|
||||
'25':
|
||||
deal: 11
|
||||
section: 4
|
||||
'24':
|
||||
deal: 8
|
||||
section: 2
|
||||
'23':
|
||||
deal: 7
|
||||
section: 2
|
||||
'22':
|
||||
deal: 4
|
||||
section: 2
|
||||
'21':
|
||||
deal: 2
|
||||
section: 0
|
||||
'19':
|
||||
deal: 9
|
||||
section: 4
|
||||
'18':
|
||||
deal: 4
|
||||
section: 4
|
||||
'17':
|
||||
deal: 2
|
||||
section: 2
|
||||
'16':
|
||||
deal: 2
|
||||
section: 3
|
||||
'15':
|
||||
deal: 2
|
||||
section: 1
|
||||
'14':
|
||||
deal: 1
|
||||
section: 0
|
||||
'12':
|
||||
deal: 8
|
||||
section: 4
|
||||
'11':
|
||||
deal: 3
|
||||
section: 4
|
||||
'10':
|
||||
deal: 1
|
||||
section: 2
|
||||
'9':
|
||||
deal: 1
|
||||
section: 3
|
||||
'8':
|
||||
deal: 1
|
||||
section: 1
|
||||
'7':
|
||||
deal: 4
|
||||
section: 0
|
||||
'5':
|
||||
deal: 7
|
||||
section: 4
|
||||
'4':
|
||||
deal: 0
|
||||
section: 4
|
||||
'3':
|
||||
deal: 0
|
||||
section: 2
|
||||
'2':
|
||||
deal: 0
|
||||
section: 3
|
||||
'1':
|
||||
deal: 0
|
||||
section: 1
|
||||
'0':
|
||||
deal: 0
|
||||
section: 0
|
@ -2,306 +2,245 @@ package me.topchetoeu.bedwars;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.topchetoeu.bedwars.commandUtility.Command;
|
||||
import me.topchetoeu.bedwars.commandUtility.CommandExecutor;
|
||||
import me.topchetoeu.bedwars.commandUtility.CommandExecutors;
|
||||
import me.topchetoeu.bedwars.engine.BedwarsPlayer;
|
||||
import me.topchetoeu.bedwars.engine.Config;
|
||||
import me.topchetoeu.bedwars.engine.Game;
|
||||
import me.topchetoeu.bedwars.engine.Team;
|
||||
import me.topchetoeu.bedwars.engine.TeamColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class Commands {
|
||||
private static File confFile = new File(Main.getInstance().getDataFolder(), "config.yml");
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static CommandExecutor kill = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Command kill(Command cmd) {
|
||||
return cmd.player("players", false).setRecursive(true).setExecutor((sender, _cmd, args) -> {
|
||||
if (Game.isStarted()) {
|
||||
for (String arg : args) {
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(arg);
|
||||
|
||||
if (p != null) {
|
||||
for (Player p : (List<Player>)args.get("players")) {
|
||||
BedwarsPlayer bwp = Game.instance.getPlayer(p);
|
||||
|
||||
if (bwp != null) {
|
||||
bwp.kill(bwp.getPlayer().getName() + " definitely died with no admin intervention.");
|
||||
}
|
||||
else sender.sendMessage("Player is not in game!");
|
||||
else return "Player is not in game!";
|
||||
}
|
||||
else sender.sendMessage("Player doesn't exist!");
|
||||
return null;
|
||||
}
|
||||
else return "The game isn't started yet";
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("The game isn't started yet");
|
||||
};
|
||||
@SuppressWarnings("deprecation")
|
||||
public static CommandExecutor revive = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Command revive(Command cmd) {
|
||||
return cmd.player("players", false).setRecursive(true).setExecutor((sender, _cmd, args) -> {
|
||||
if (Game.isStarted()) {
|
||||
for (String arg : args) {
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(arg);
|
||||
|
||||
if (p != null) {
|
||||
for (Player p : (List<Player>)args.get("players")) {
|
||||
BedwarsPlayer bwp = Game.instance.getPlayer(p);
|
||||
|
||||
if (bwp != null) {
|
||||
bwp.revive();
|
||||
Bukkit.broadcastMessage("Player " + p.getName() + " revived!");
|
||||
return null;
|
||||
}
|
||||
else sender.sendMessage("Player is not in game!");
|
||||
else return "Player is not in game!";
|
||||
}
|
||||
else sender.sendMessage("Player doesn't exist!");
|
||||
return null;
|
||||
}
|
||||
else return "The game isn't started yet";
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("The game isn't started yet");
|
||||
};
|
||||
|
||||
public static CommandExecutor start = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
if (args.length == 0) {
|
||||
public static Command start(Command cmd) {
|
||||
return cmd.setExecutor((sender, _cmd, args) -> {
|
||||
if (!Game.isStarted()) {
|
||||
Game.start();
|
||||
sender.sendMessage("Started the game!");
|
||||
return null;
|
||||
}
|
||||
else sender.sendMessage("The game is already started");
|
||||
else return "The game is already started";
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("Invalid command syntax. No parameters required!");
|
||||
};
|
||||
public static CommandExecutor stop = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
if (args.length == 0) {
|
||||
public static Command stop(Command cmd) {
|
||||
return cmd.setExecutor((sender, _cmd, args) -> {
|
||||
if (Game.isStarted()) {
|
||||
Game.stop();
|
||||
sender.sendMessage("Stopped the game!");
|
||||
return null;
|
||||
}
|
||||
else sender.sendMessage("The game is not started");
|
||||
else return "The game is not started";
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("Invalid command syntax. No parameters required!");
|
||||
};
|
||||
|
||||
public static CommandExecutor baseAdd = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
if (args.length == 6 && args[5].length() == 1) {
|
||||
private static Command basesArg() {
|
||||
return Command.createCollection("team", () -> Config.instance.getColors()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
TeamColor::getName,
|
||||
v -> v
|
||||
)), false
|
||||
);
|
||||
}
|
||||
|
||||
public static Command baseAdd(Command cmd) {
|
||||
return cmd.string("name", false)._int("red")._int("green")._int("blue")._enum("color", org.bukkit.ChatColor.class, true)._enum("wool", Material.class, true)
|
||||
.setExecutor((sender, _cmd, args) -> {
|
||||
if (!Game.isStarted()) {
|
||||
if (Utility.isParsable(args[2])) {
|
||||
if (Utility.isParsable(args[3])) {
|
||||
if (Utility.isParsable(args[4])) {
|
||||
String name = args.get("name").toString().toLowerCase();
|
||||
Material wool = (Material)args.get("wool");
|
||||
org.bukkit.ChatColor bukkitChatColor = (org.bukkit.ChatColor)args.get("color");
|
||||
int r = (int)args.get("red"),
|
||||
g = (int)args.get("green"),
|
||||
b = (int)args.get("blue");
|
||||
|
||||
ChatColor chatColor = Utility.bukkitToBungeeColor(bukkitChatColor);
|
||||
|
||||
String name = args[0];
|
||||
Material wool = Material.getMaterial(args[1].toString());
|
||||
char chatId = args[5].charAt(0);
|
||||
if (wool != null) {
|
||||
if (Config.instance.getColor(name.toLowerCase()) == null) {
|
||||
Config.instance.getColors().add(new TeamColor(name.toLowerCase(), wool,
|
||||
Color.fromRGB(
|
||||
Integer.parseInt(args[2]),
|
||||
Integer.parseInt(args[3]),
|
||||
Integer.parseInt(args[4])
|
||||
),
|
||||
chatId
|
||||
));
|
||||
Config.instance.getColors().add(new TeamColor(name, wool, Color.fromRGB(r, g, b), chatColor));
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("New base was created!");
|
||||
return null;
|
||||
}
|
||||
else sender.sendMessage("Base with this name already exists!");
|
||||
else return "Base with this name already exists!";
|
||||
}
|
||||
else sender.sendMessage("The material '" + args[1] + " was not found!");
|
||||
} else sender.sendMessage("blue must be a valid number between 0 and 255!");
|
||||
} else sender.sendMessage("green must be a valid number between 0 and 255!");
|
||||
} else sender.sendMessage("red must be a valid number between 0 and 255!");
|
||||
else return "Can't make modifications to the map while a game is ongoing!";
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("Can't make modifications to the map while a game is ongoing!");
|
||||
}
|
||||
else sender.sendMessage("Invalid command syntax. Syntax: /bw conf base new <name> <woolId> <chatId>");
|
||||
};
|
||||
|
||||
public static CommandExecutor baseRemove = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
if (args.length == 1) {
|
||||
TeamColor color = Config.instance.getColor(args[0]);
|
||||
if (color != null) {
|
||||
public static Command baseRemove(Command cmd) {
|
||||
return cmd
|
||||
.addChild(basesArg())
|
||||
.setExecutor((sender, _cmd, args) -> {
|
||||
TeamColor color = (TeamColor)args.get("team");
|
||||
Config.instance.getColors().remove(color);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("Base removed!");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("Base doesn't exist!");
|
||||
}
|
||||
else sender.sendMessage("Invalid syntax! Syntax: /bw conf base del <name>");
|
||||
};
|
||||
public static CommandExecutor baseSetSpawn = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
boolean aligned = args.length == 2 && args[1].equals("aligned");
|
||||
public static Command baseSetSpawn(Command cmd) {
|
||||
return cmd
|
||||
.addChild(basesArg())
|
||||
.location("location")
|
||||
.setExecutor((sender, _cmd, args) -> {
|
||||
TeamColor color = (TeamColor)args.get("team");
|
||||
Location loc = (Location)args.get("location");
|
||||
|
||||
if (args.length == 1 || aligned) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player)sender;
|
||||
|
||||
TeamColor color = Config.instance.getColor(args[0]);
|
||||
if (color != null) {
|
||||
Location loc = p.getLocation();
|
||||
if (aligned) {
|
||||
loc.setX(loc.getBlockX() + 0.5);
|
||||
loc.setZ(loc.getBlockZ() + 0.5);
|
||||
}
|
||||
color.setSpawnLocation(loc);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("Base spawn set to your current location");
|
||||
}
|
||||
else sender.sendMessage("Base doesn't exist!");
|
||||
sender.sendMessage("Base spawn set");
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("This commands is for players only!");
|
||||
}
|
||||
else sender.sendMessage("Invalid syntax! Syntax: /bw conf base spawn [aligned]");
|
||||
};
|
||||
public static CommandExecutor baseSetGenerator = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
boolean aligned = args.length == 2 && args[1].equals("aligned");
|
||||
public static Command baseSetGenerator(Command cmd) {
|
||||
return cmd
|
||||
.addChild(basesArg())
|
||||
.location("location")
|
||||
.setExecutor((sender, _cmd, args) -> {
|
||||
TeamColor color = (TeamColor)args.get("team");
|
||||
Location loc = (Location)args.get("location");
|
||||
|
||||
if (args.length == 1 || aligned) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player)sender;
|
||||
|
||||
TeamColor color = Config.instance.getColor(args[0]);
|
||||
if (color != null) {
|
||||
Location loc = p.getLocation();
|
||||
if (aligned) {
|
||||
loc.setX(loc.getBlockX() + 0.5);
|
||||
loc.setZ(loc.getBlockZ() + 0.5);
|
||||
}
|
||||
color.setGeneratorLocation(loc);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("Base generator set to your current location");
|
||||
}
|
||||
else sender.sendMessage("Base doesn't exist!");
|
||||
sender.sendMessage("Base generator set");
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("This commands is for players only!");
|
||||
}
|
||||
else sender.sendMessage("Invalid syntax! Syntax: /bw conf base gen [aligned]");
|
||||
};
|
||||
public static CommandExecutor baseSetBed = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
boolean aligned = args.length == 2 && args[1].equals("aligned");
|
||||
public static Command baseSetBed(Command cmd) {
|
||||
return cmd
|
||||
.addChild(basesArg())
|
||||
.location("location")
|
||||
.setExecutor((sender, _cmd, args) -> {
|
||||
TeamColor color = (TeamColor)args.get("team");
|
||||
Location loc = (Location)args.get("location");
|
||||
|
||||
if (args.length == 1 || aligned) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player)sender;
|
||||
|
||||
TeamColor color = Config.instance.getColor(args[0]);
|
||||
if (color != null) {
|
||||
Location loc = p.getLocation();
|
||||
if (aligned) {
|
||||
loc.setX(loc.getBlockX() + 0.5);
|
||||
loc.setZ(loc.getBlockZ() + 0.5);
|
||||
}
|
||||
color.setBedLocation(loc);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("Base bed set to your current location");
|
||||
}
|
||||
else sender.sendMessage("Base doesn't exist!");
|
||||
sender.sendMessage("Base bed set");
|
||||
|
||||
return null;
|
||||
});
|
||||
// );
|
||||
}
|
||||
else sender.sendMessage("This commands is for players only!");
|
||||
}
|
||||
else sender.sendMessage("Invalid syntax! Syntax: /bw conf base bed [aligned]");
|
||||
};
|
||||
public static CommandExecutor baseList = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
if (args.length == 0) {
|
||||
ArrayList<TeamColor> colors = Config.instance.getColors();
|
||||
public static Command baseList(Command cmd) {
|
||||
return cmd
|
||||
.setExecutor((sender, _cmd, args) -> {
|
||||
List<TeamColor> colors = Config.instance.getColors();
|
||||
|
||||
if (colors.size() != 0) {
|
||||
sender.sendMessage("Bases:");
|
||||
for (TeamColor color : colors) {
|
||||
sender.sendMessage("§" + color.getChatColor() + color.getName() + "§r" + (
|
||||
color.isFullySpecified() ? "" : " (not fully specified)"
|
||||
));
|
||||
ComponentBuilder cb = new ComponentBuilder().append(color.getName()).color(color.getChatColor());
|
||||
if (!color.isFullySpecified()) cb.append(" (not fully specified)").reset().italic(true);
|
||||
sender.spigot().sendMessage(cb.create());
|
||||
}
|
||||
}
|
||||
else sender.sendMessage("No bases found.");
|
||||
}
|
||||
else sender.sendMessage("Invalid syntax! No parameters required");
|
||||
};
|
||||
|
||||
public static CommandExecutor breakBed = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
if (!Game.isStarted()) {
|
||||
sender.sendMessage("§4A game hasn't been started yet.");
|
||||
return;
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Command breakBed(Command cmd) {
|
||||
return cmd
|
||||
.addChild(basesArg()).setRecursive(true)
|
||||
.setExecutor((sender, _cmd, args) -> {
|
||||
if (!Game.isStarted()) return "A game hasn't been started yet.";
|
||||
|
||||
List<TeamColor> colors = (List<TeamColor>)args.get("team");
|
||||
ArrayList<Team> teams = new ArrayList<>();
|
||||
|
||||
for (String arg : args) {
|
||||
TeamColor color = Config.instance.getColor(arg);
|
||||
|
||||
if (color == null) {
|
||||
sender.sendMessage(String.format("§4The team color §l§4%s§r§4 doesn't exist.", arg));
|
||||
return;
|
||||
}
|
||||
|
||||
for (TeamColor color : colors) {
|
||||
Team team = Game.instance.getTeam(color);
|
||||
|
||||
if (team == null) {
|
||||
sender.sendMessage(String.format("§6The team color §l§4%s§r§4 isn't in the game.", arg));
|
||||
return "The team color %s isn't in the game.".formatted(color.getName());
|
||||
}
|
||||
|
||||
teams.add(team);
|
||||
}
|
||||
|
||||
for (Team team : teams) {
|
||||
if (!team.destroyBed(null))
|
||||
sender.sendMessage(String.format("§4The %s's bed is already destroyed.", team.getTeamColor().getName()));
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static CommandExecutor createDiamondGen = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
if (args.length > 1) {
|
||||
sender.sendMessage("§4Invalid syntax!§r Syntax: /bw config gen diamond [aligned]");
|
||||
return;
|
||||
team.destroyBed(null);
|
||||
}
|
||||
|
||||
boolean aligned = args.length == 1 && args[0] == "aligned";
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player)sender;
|
||||
|
||||
Location loc = p.getLocation();
|
||||
if (aligned) {
|
||||
loc.setX(loc.getBlockX() + 0.5);
|
||||
loc.setZ(loc.getBlockZ() + 0.5);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public static Command createDiamondGen(Command cmd) {
|
||||
return cmd.location("location").setExecutor((sender, _cmd, args) -> {
|
||||
Location loc = (Location)args.get("location");
|
||||
Config.instance.getDiamondGenerators().add(loc);
|
||||
Config.instance.save(confFile);
|
||||
|
||||
p.sendMessage("§aGenerator added!");
|
||||
sender.sendMessage("§aGenerator added!");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("§4Only a player may execute this command.");
|
||||
};
|
||||
public static CommandExecutor createEmeraldGen = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
||||
if (args.length > 1) {
|
||||
sender.sendMessage("§4Invalid syntax!§r Syntax: /bw config gen emerald [aligned]");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean aligned = args.length == 1 && args[0] == "aligned";
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player)sender;
|
||||
|
||||
Location loc = p.getLocation();
|
||||
if (aligned) {
|
||||
loc.setX(loc.getBlockX() + 0.5);
|
||||
loc.setZ(loc.getBlockZ() + 0.5);
|
||||
}
|
||||
|
||||
public static Command createEmeraldGen(Command cmd) {
|
||||
return cmd.location("location").setExecutor((sender, _cmd, args) -> {
|
||||
Location loc = (Location)args.get("location");
|
||||
Config.instance.getEmeraldGenerators().add(loc);
|
||||
Config.instance.save(confFile);
|
||||
|
||||
p.sendMessage("§aGenerator added!");
|
||||
sender.sendMessage("§aGenerator added!");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
public static Command clearGens(Command cmd) {
|
||||
return cmd.setExecutor((sender, _cmd, args) -> {
|
||||
Config.instance.getEmeraldGenerators().clear();
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("§aGenerators cleared!");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
else sender.sendMessage("§4Only a player may execute this command.");
|
||||
};
|
||||
|
||||
public static CommandExecutor _default = CommandExecutors.message("For help do /bw help");
|
||||
}
|
||||
|
@ -1,26 +1,18 @@
|
||||
package me.topchetoeu.bedwars;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@ -54,7 +46,7 @@ public class Main extends JavaPlugin implements Listener {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private File confFile = new File(getDataFolder(), "config.yml");
|
||||
// private File confFile = new File(getDataFolder(), "config.yml");
|
||||
private int getGameSize() {
|
||||
return Config.instance.getTeamSize() * Config.instance.getColors().size();
|
||||
}
|
||||
@ -135,36 +127,12 @@ public class Main extends JavaPlugin implements Listener {
|
||||
getDataFolder().mkdir();
|
||||
File conf = new File(getDataFolder(), "config.yml");
|
||||
if (!conf.exists())
|
||||
try {
|
||||
YamlConfiguration.loadConfiguration(
|
||||
new InputStreamReader(
|
||||
getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("config.yml")
|
||||
)
|
||||
).save(confFile);
|
||||
}
|
||||
catch (IOException e) { /* Everything is fine */ }
|
||||
|
||||
// Deprecation warnings are for beginners
|
||||
conf.createNewFile();
|
||||
Config.load(conf);
|
||||
File defaultFavs = new File(getDataFolder(), "default-favourites.yml");
|
||||
|
||||
if (!defaultFavs.exists()) {
|
||||
try {
|
||||
OutputStream w = new FileOutputStream(defaultFavs);
|
||||
InputStream r = getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("default-favourites.yml");
|
||||
|
||||
w.write(r.readAllBytes());
|
||||
|
||||
w.close();
|
||||
r.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!defaultFavs.exists())
|
||||
defaultFavs.createNewFile();
|
||||
|
||||
File favsDir = new File(getDataFolder(), "favourites");
|
||||
|
||||
@ -197,110 +165,58 @@ public class Main extends JavaPlugin implements Listener {
|
||||
v.setAI(false);
|
||||
});
|
||||
|
||||
Command cmd = new Command("bedwars", "bw").setExecutor(Commands._default);
|
||||
cmd
|
||||
.attachCommand(new Command("help")
|
||||
.setExecutor(CommandExecutors.help(cmd))
|
||||
.setHelpMessage("Shows help for the command")
|
||||
)
|
||||
.attachCommand(new Command("start")
|
||||
.setExecutor(Commands.start)
|
||||
.setHelpMessage("Starts the game")
|
||||
)
|
||||
.attachCommand(new Command("stop")
|
||||
.setExecutor(Commands.stop)
|
||||
.setHelpMessage("Stops the game, noone wins")
|
||||
)
|
||||
.attachCommand(new Command("respawn", "revive")
|
||||
.setExecutor(Commands.revive)
|
||||
.setHelpMessage("Respawns a spectator, if he has a bed, he is immediatly respawned"))
|
||||
.attachCommand(new Command("breakbed", "eliminateteam")
|
||||
.setExecutor(Commands.breakBed)
|
||||
.setHelpMessage("Destoys the bed of a team")
|
||||
)
|
||||
.attachCommand(new Command("eliminate")
|
||||
.setHelpMessage("Eliminates a player")
|
||||
)
|
||||
.attachCommand(new Command("kill")
|
||||
.setExecutor(Commands.kill)
|
||||
.setHelpMessage("Kills a player")
|
||||
)
|
||||
.attachCommand(new Command("killteam")
|
||||
.setHelpMessage("Kills all players of a team")
|
||||
)
|
||||
.attachCommand(new Command("villagertools", "villager", "trader")
|
||||
.setExecutor((sender, _cmd, alias, args) -> {
|
||||
if (args.length == 0) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player)sender;
|
||||
Command cmd = Command.createLiteral("bedwars", "bw");
|
||||
|
||||
p.getInventory().addItem(Utility.namedItem(new ItemStack(Material.VILLAGER_SPAWN_EGG), "§rTrader spawner"));
|
||||
p.getInventory().addItem(Utility.namedItem(new ItemStack(Material.STICK), "§rTrader eradicator"));
|
||||
}
|
||||
}
|
||||
})
|
||||
.setHelpMessage("Gives you tools to manage traders")
|
||||
)
|
||||
.attachCommand(new Command("config", "conf", "settings")
|
||||
.setExecutor(Commands._default)
|
||||
.setHelpMessage("Command for configuring the map")
|
||||
.attachCommand(new Command("spawn")
|
||||
.setHelpMessage("Sets the spawn at which the platform is going to be spawned, and where spectators are going to be spawned")
|
||||
)
|
||||
.attachCommand(new Command("base", "b")
|
||||
.setExecutor(Commands._default)
|
||||
.setHelpMessage("Command for configuring separate bases")
|
||||
.attachCommand(new Command("new", "add", "create", "c")
|
||||
.setExecutor(Commands.baseAdd)
|
||||
.setHelpMessage("Creates a base with a color, chat id and a wool id. NOTE: for chat id, do the following: if in chat the color you want is &2, specify just '2'")
|
||||
)
|
||||
.attachCommand(new Command("remove", "delete", "del", "d")
|
||||
.setExecutor(Commands.baseRemove)
|
||||
.setHelpMessage("Removes a base with the selected name")
|
||||
)
|
||||
.attachCommand(new Command("setbed", "bed", "b")
|
||||
.setExecutor(Commands.baseSetBed)
|
||||
.setHelpMessage("Sets the location of the bed. Any broken bed within 5 blocks of the specified location will trigger the breaking of the team's bed")
|
||||
)
|
||||
.attachCommand(new Command("setgenerator", "generator", "setgen", "gen", "g")
|
||||
.setExecutor(Commands.baseSetGenerator)
|
||||
.setHelpMessage("Sets the location of the generator. Anyone within 2 blocks of it will pick up the produced items")
|
||||
)
|
||||
.attachCommand(new Command("setspawn", "spawn", "s")
|
||||
.setExecutor(Commands.baseSetSpawn)
|
||||
.setHelpMessage("Sets the location where players of the team will respawn")
|
||||
)
|
||||
.attachCommand(new Command("list", "l")
|
||||
.setExecutor(Commands.baseList)
|
||||
.setHelpMessage("Lists all bases")
|
||||
)
|
||||
)
|
||||
.attachCommand(new Command("generator", "gen", "g")
|
||||
.setExecutor(Commands._default)
|
||||
.setHelpMessage("Command for configuring the global generators")
|
||||
.attachCommand(new Command("diamond", "d")
|
||||
.setExecutor(Commands.createDiamondGen)
|
||||
.setHelpMessage("Creates a diamond generator in (approximately) your position")
|
||||
)
|
||||
.attachCommand(new Command("emerald", "e")
|
||||
.setExecutor(Commands.createEmeraldGen)
|
||||
.setHelpMessage("Creates a emerald generator in (approximately) your position")
|
||||
)
|
||||
.attachCommand(new Command("remove", "delete", "del", "r")
|
||||
.setHelpMessage("Deletes all generators within 5 block of your position")
|
||||
)
|
||||
)
|
||||
)
|
||||
.attachCommand(new Command("diemydarling")
|
||||
.setExecutor((a, b, c, d) -> {
|
||||
Bukkit.getWorld("world")
|
||||
.getEntities()
|
||||
.stream()
|
||||
.filter(v -> v instanceof ArmorStand)
|
||||
.forEach(v -> v.remove());
|
||||
})
|
||||
)
|
||||
.register(this);
|
||||
cmd.literal("help").setExecutor(CommandExecutors.help()).string("args", false).setRecursive(true).setExecutor(CommandExecutors.help());
|
||||
Commands.start(cmd.literal("start"));
|
||||
Commands.stop(cmd.literal("stop"));
|
||||
|
||||
Commands.kill(cmd.literal("kill"));
|
||||
Commands.revive(cmd.literal("revive"));
|
||||
|
||||
Command config = cmd.literal("configuration", "config", "conf");
|
||||
Command base = config.literal("base");
|
||||
Command generator = config.literal("generator", "gen");
|
||||
|
||||
Commands.baseAdd(base.literal("add"));
|
||||
Commands.baseRemove(base.literal("remove"));
|
||||
Commands.baseSetSpawn(base.literal("setspawn", "spawn"));
|
||||
Commands.baseSetGenerator(base.literal("setgenerator", "generator", "gen"));
|
||||
Commands.baseSetBed(base.literal("setbed", "bed"));
|
||||
Commands.baseList(base.literal("list", "l"));
|
||||
|
||||
Commands.createDiamondGen(generator.literal("diamond"));
|
||||
Commands.createEmeraldGen(generator.literal("emerald", "em"));
|
||||
Commands.clearGens(generator.literal("emerald", "em"));
|
||||
|
||||
Commands.breakBed(cmd.literal("breakbed", "cheat", "bedishonest", "abusepowers"));
|
||||
|
||||
cmd.register(this);
|
||||
// .attachCommand(new Command("respawn", "revive")
|
||||
// .setExecutor(Commands.revive)
|
||||
// .setHelpMessage("Respawns a spectator, if he has a bed, he is immediatly respawned"))
|
||||
// .attachCommand(new Command("breakbed", "eliminateteam")
|
||||
// .setExecutor(Commands.breakBed)
|
||||
// .setHelpMessage("Destoys the bed of a team")
|
||||
// )
|
||||
// .attachCommand(new Command("eliminate")
|
||||
// .setHelpMessage("Eliminates a player")
|
||||
// )
|
||||
// .attachCommand(new Command("killteam")
|
||||
// .setHelpMessage("Kills all players of a team")
|
||||
// )
|
||||
// .attachCommand(new Command("villagertools", "villager", "trader")
|
||||
// .setExecutor((sender, _cmd, alias, args) -> {
|
||||
// if (args.length == 0) {
|
||||
// if (sender instanceof Player) {
|
||||
// Player p = (Player)sender;
|
||||
// Traders.instance.give(p);
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .setHelpMessage("Gives you tools to manage traders")
|
||||
// )
|
||||
// .register(this);
|
||||
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
|
||||
public class Utility {
|
||||
public static void sendTitle(Player p, String title, String subtitle, int fadeIn, int duration, int fadeout) {
|
||||
p.sendTitle(title, subtitle, fadeIn, duration, fadeout);
|
||||
@ -54,12 +57,11 @@ public class Utility {
|
||||
i.setItemMeta(meta);
|
||||
return i;
|
||||
}
|
||||
public static String getItemName(Material item) {
|
||||
return CraftItemStack.asNMSCopy(new ItemStack(item)).n();
|
||||
public static TranslatableComponent getItemName(Material item) {
|
||||
return new TranslatableComponent(CraftItemStack.asNMSCopy(new ItemStack(item)).n());
|
||||
}
|
||||
public static String getItemName(ItemStack item) {
|
||||
if (item.getItemMeta().hasDisplayName()) return item.getItemMeta().getDisplayName();
|
||||
return CraftItemStack.asNMSCopy(item).n();
|
||||
public static TranslatableComponent getItemName(ItemStack item) {
|
||||
return new TranslatableComponent(CraftItemStack.asNMSCopy(new ItemStack(item)).n());
|
||||
}
|
||||
public static void takeOne(Player p, EquipmentSlot e) {
|
||||
ItemStack i = p.getInventory().getItem(e);
|
||||
@ -179,4 +181,54 @@ public class Utility {
|
||||
if (obj == null) obj = "null";
|
||||
p.sendMessage(obj.toString());
|
||||
}
|
||||
public static ChatColor bukkitToBungeeColor(org.bukkit.ChatColor bukkitChatColor) {
|
||||
switch (bukkitChatColor) {
|
||||
case RED:
|
||||
return ChatColor.RED;
|
||||
case AQUA:
|
||||
return ChatColor.AQUA;
|
||||
case BLACK:
|
||||
return ChatColor.BLACK;
|
||||
case BLUE:
|
||||
return ChatColor.BLUE;
|
||||
case BOLD:
|
||||
return ChatColor.BOLD;
|
||||
case DARK_AQUA:
|
||||
return ChatColor.DARK_AQUA;
|
||||
case DARK_BLUE:
|
||||
return ChatColor.DARK_BLUE;
|
||||
case DARK_GRAY:
|
||||
return ChatColor.DARK_GRAY;
|
||||
case DARK_GREEN:
|
||||
return ChatColor.DARK_GREEN;
|
||||
case DARK_PURPLE:
|
||||
return ChatColor.DARK_PURPLE;
|
||||
case DARK_RED:
|
||||
return ChatColor.DARK_RED;
|
||||
case GOLD:
|
||||
return ChatColor.GOLD;
|
||||
case GRAY:
|
||||
return ChatColor.GRAY;
|
||||
case GREEN:
|
||||
return ChatColor.GREEN;
|
||||
case ITALIC:
|
||||
return ChatColor.ITALIC;
|
||||
case LIGHT_PURPLE:
|
||||
return ChatColor.LIGHT_PURPLE;
|
||||
case MAGIC:
|
||||
return ChatColor.MAGIC;
|
||||
case RESET:
|
||||
return ChatColor.RESET;
|
||||
case STRIKETHROUGH:
|
||||
return ChatColor.STRIKETHROUGH;
|
||||
case UNDERLINE:
|
||||
return ChatColor.UNDERLINE;
|
||||
case WHITE:
|
||||
return ChatColor.WHITE;
|
||||
case YELLOW:
|
||||
return ChatColor.YELLOW;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,56 @@
|
||||
package me.topchetoeu.bedwars.commandUtility;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import me.topchetoeu.bedwars.commandUtility.args.ArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.ArgParserRes;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.CollectionArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.CollectionProvider;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.EnumArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.IntArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.LiteralArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.LocationArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.PlayerArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.StringArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.Suggestions;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class Command {
|
||||
private String[] aliases;
|
||||
private String name;
|
||||
private String helpMessage;
|
||||
private CommandExecutor fallbackExecutor;
|
||||
private HashSet<Command> attachedCommands = new HashSet<>();
|
||||
private CommandExecutor executor;
|
||||
private HashSet<Command> children = new HashSet<>();
|
||||
private ArgParser parser;
|
||||
private boolean recursive = false;
|
||||
|
||||
private JavaPlugin parent = null;
|
||||
|
||||
public String[] getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
private Set<JavaPlugin> parents = new HashSet<>();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean attachedToAnyPlugin() {
|
||||
return parents.size() > 0;
|
||||
}
|
||||
public Set<JavaPlugin> getParentPlugins() {
|
||||
return Collections.unmodifiableSet(parents);
|
||||
}
|
||||
|
||||
public ArgParser getParser() {
|
||||
return parser;
|
||||
}
|
||||
|
||||
public String getHelpMessage() {
|
||||
return helpMessage;
|
||||
}
|
||||
@ -31,116 +59,264 @@ public class Command {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandExecutor getFallbackExecutor() {
|
||||
return fallbackExecutor;
|
||||
public CommandExecutor getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
public Command setExecutor(CommandExecutor val) {
|
||||
fallbackExecutor = val;
|
||||
executor = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Command attachCommand(Command cmd) {
|
||||
public Command addChild(Command cmd) {
|
||||
if (cmd == null) throw new RuntimeException("cmd is null");
|
||||
attachedCommands.add(cmd);
|
||||
children.add(cmd);
|
||||
return cmd;
|
||||
}
|
||||
public Command removeChild(Command cmd) {
|
||||
if (cmd == null) throw new RuntimeException("cmd is null");
|
||||
children.remove(cmd);
|
||||
return this;
|
||||
}
|
||||
public Command detachCommand(Command cmd) {
|
||||
if (cmd == null) throw new RuntimeException("cmd is null");
|
||||
attachedCommands.remove(cmd);
|
||||
return this;
|
||||
}
|
||||
public boolean commandAttached(Command cmd) {
|
||||
public boolean hasChild(Command cmd) {
|
||||
if (cmd == null) return false;
|
||||
return attachedCommands.contains(cmd);
|
||||
return children.contains(cmd);
|
||||
}
|
||||
public Command[] getAttachedCommands() {
|
||||
return attachedCommands.toArray(Command[]::new);
|
||||
public Set<Command> getChildren() {
|
||||
return Collections.unmodifiableSet(children);
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, String alias, String[] args) {
|
||||
Command cmd;
|
||||
if (args.length == 0) cmd = null;
|
||||
else cmd = getAttachedCommand(args[0]);
|
||||
|
||||
String[] newArgs;
|
||||
if (args.length <= 1) newArgs = new String[0];
|
||||
else {
|
||||
newArgs = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, newArgs, 0, args.length - 1);
|
||||
public Command setRecursive(boolean val) {
|
||||
recursive = val;
|
||||
return this;
|
||||
}
|
||||
public boolean isRecursive() {
|
||||
return recursive;
|
||||
}
|
||||
|
||||
if (cmd != null)
|
||||
cmd.execute(sender, args[0], newArgs);
|
||||
else if (fallbackExecutor != null) fallbackExecutor.execute(
|
||||
sender, this,
|
||||
alias, args
|
||||
@SuppressWarnings("unchecked")
|
||||
public void execute(CommandSender sender, String[] _args) {
|
||||
Command toExecute = this;
|
||||
|
||||
Hashtable<String, Object> newArgs = new Hashtable<>();
|
||||
|
||||
List<String> args = new ArrayList<>();
|
||||
Collections.addAll(args, _args);
|
||||
|
||||
String err = null;
|
||||
|
||||
while (args.size() > 0) {
|
||||
Command newCmd = null;
|
||||
Set<Command> children = toExecute.getChildren();
|
||||
if (toExecute.isRecursive()) children = Collections.singleton(toExecute);
|
||||
for (Command cmd : children) {
|
||||
ArgParser parser = cmd.getParser();
|
||||
ArgParserRes res = parser.parse(sender, args);
|
||||
|
||||
if (res.hasError()) err = res.getError();
|
||||
else if (res.hasSucceeded()) {
|
||||
for (int i = 0; i < res.getTakenCount(); i++) {
|
||||
if (args.size() == 0) break;
|
||||
args.remove(0);
|
||||
}
|
||||
|
||||
if (res.hasResult()) {
|
||||
if (cmd.recursive) {
|
||||
if (!newArgs.containsKey(cmd.name)) newArgs.put(cmd.name, new ArrayList<>());
|
||||
((List<Object>)newArgs.get(cmd.name)).add(res.getResult());
|
||||
}
|
||||
else newArgs.put(cmd.name, res.getResult());
|
||||
}
|
||||
newCmd = cmd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (newCmd == null) {
|
||||
toExecute = null;
|
||||
break;
|
||||
}
|
||||
toExecute = newCmd;
|
||||
}
|
||||
|
||||
if (toExecute == null) err = "Invalid command syntax.";
|
||||
else if (toExecute.getExecutor() == null) err = "Incomplete command.";
|
||||
|
||||
if (err != null) sender.spigot().sendMessage(new ComponentBuilder()
|
||||
.append("Error: ")
|
||||
.color(ChatColor.DARK_RED)
|
||||
.append(err)
|
||||
.color(ChatColor.RED)
|
||||
.create()
|
||||
);
|
||||
else sender.sendMessage("This command doesn't do anything :(");
|
||||
else {
|
||||
if (toExecute.isRecursive() && !newArgs.containsKey(toExecute.name)) newArgs.put(toExecute.name, new ArrayList<>());
|
||||
err = toExecute.getExecutor().execute(sender, this, newArgs);
|
||||
if (err != null) sender.spigot().sendMessage(new ComponentBuilder()
|
||||
.append("Error: ")
|
||||
.color(ChatColor.DARK_RED)
|
||||
.append(err)
|
||||
.color(ChatColor.RED)
|
||||
.create()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> tabComplete(CommandSender sender, String[] _args) {
|
||||
Command toComplete = this;
|
||||
|
||||
List<String> args = new ArrayList<>();
|
||||
Collections.addAll(args, _args);
|
||||
|
||||
int index = 1;
|
||||
|
||||
while (args.size() > 0) {
|
||||
boolean found = false;
|
||||
index++;
|
||||
for (Command cmd : toComplete.children) {
|
||||
ArgParser parser = cmd.getParser();
|
||||
ArgParserRes res = parser.parse(sender, args);
|
||||
if (res.hasSucceeded()) {
|
||||
for (int i = 0; i < res.getTakenCount(); i++) {
|
||||
if (args.size() == 0) break;
|
||||
args.remove(0);
|
||||
}
|
||||
toComplete = cmd;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) break;
|
||||
}
|
||||
|
||||
if (args.size() == 0) return null;
|
||||
|
||||
Suggestions suggestions = new Suggestions();
|
||||
|
||||
for (Command cmd : toComplete.children) {
|
||||
cmd.getParser().addCompleteSuggestions(sender, args, suggestions);
|
||||
}
|
||||
|
||||
if (suggestions.hasError() && !suggestions.getSuggestions().contains(args.get(0))) {
|
||||
sender.spigot().sendMessage(new ComponentBuilder()
|
||||
.append("Error (argument %d): ".formatted(index + 1))
|
||||
.color(ChatColor.DARK_RED)
|
||||
.append(suggestions.getError())
|
||||
.color(ChatColor.RED)
|
||||
.create()
|
||||
);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
List<String> _suggestions = new ArrayList<>(suggestions.getSuggestions());
|
||||
return _suggestions;
|
||||
}
|
||||
}
|
||||
|
||||
public Command register(JavaPlugin pl) {
|
||||
if (pl == parent) throw new IllegalArgumentException("The command is already attached to the given plugin");
|
||||
if (!(parser instanceof LiteralArgParser))
|
||||
throw new IllegalArgumentException("Only a command with a literal parser may be registered.");
|
||||
if (parents.contains(pl)) throw new IllegalArgumentException("The command is already attached to the given plugin");
|
||||
if (pl == null) throw new RuntimeException("pl is null");
|
||||
parent = pl;
|
||||
pl.getCommand(name).setAliases(Arrays.asList(aliases));
|
||||
pl.getCommand(name).setExecutor(new org.bukkit.command.CommandExecutor() {
|
||||
parents.add(pl);
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String alias, String[] args) {
|
||||
execute(sender, alias, args);
|
||||
LiteralArgParser parser = (LiteralArgParser)this.parser;
|
||||
String name = parser.getLiteral();
|
||||
|
||||
pl.getCommand(name).setAliases(parser.getAliases());
|
||||
pl.getCommand(name).setExecutor((sender, cmd, alias, args) -> {
|
||||
execute(sender, args);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
pl.getCommand(name).setTabCompleter((sender, cmd, alias, args) -> {
|
||||
return tabComplete(sender, args);
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Command getAttachedCommand(String alias) {
|
||||
String newAlias = alias.toLowerCase();
|
||||
for (Command command : attachedCommands) {
|
||||
if (command.name.equals(newAlias) || Arrays.stream(command.aliases).anyMatch(v -> v.equals(newAlias)))
|
||||
return command;
|
||||
}
|
||||
return null;
|
||||
public Command(String name, ArgParser parser) {
|
||||
this.name = name;
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public Command(String name, String alias) {
|
||||
this.name = name;
|
||||
this.aliases = new String[] { alias };
|
||||
public Command literal(String name) {
|
||||
Command cmd = createLiteral(name);
|
||||
addChild(cmd);
|
||||
return cmd;
|
||||
}
|
||||
public Command(String name, String... aliases) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
public Command literal(String name, String ...aliases) {
|
||||
Command cmd = createLiteral(name, aliases);
|
||||
addChild(cmd);
|
||||
return cmd;
|
||||
}
|
||||
public Command(String name, CommandExecutor executor, String... aliases) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
this.fallbackExecutor = executor;
|
||||
public Command location(String name) {
|
||||
Command cmd = createLocation(name);
|
||||
addChild(cmd);
|
||||
return cmd;
|
||||
}
|
||||
public Command(String name, String alias, Command... commands) {
|
||||
this.name = name;
|
||||
this.aliases = new String[] { alias };
|
||||
|
||||
for (Command cmd : commands) {
|
||||
attachCommand(cmd);
|
||||
public Command _enum(String name, Class<? extends Enum<?>> enumType, boolean caseInsensitive) {
|
||||
Command cmd = createEnum(name, enumType, caseInsensitive);
|
||||
addChild(cmd);
|
||||
return cmd;
|
||||
}
|
||||
public Command player(String name, boolean caseInsensitive) {
|
||||
Command cmd = createPlayer(name, caseInsensitive);
|
||||
addChild(cmd);
|
||||
return cmd;
|
||||
}
|
||||
public Command(String name, String[] aliases, Command... commands) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
|
||||
for (Command cmd : commands) {
|
||||
attachCommand(cmd);
|
||||
public Command string(String name, boolean greedy) {
|
||||
Command cmd = createString(name, greedy);
|
||||
addChild(cmd);
|
||||
return cmd;
|
||||
}
|
||||
public Command _int(String name) {
|
||||
Command cmd = createInt(name);
|
||||
addChild(cmd);
|
||||
return cmd;
|
||||
}
|
||||
public Command(String name, String[] aliases, CommandExecutor executor, Command... commands) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
fallbackExecutor = executor;
|
||||
|
||||
for (Command cmd : commands) {
|
||||
attachCommand(cmd);
|
||||
public Command collection(String name, SimpleCollectionQuery query, boolean caseInsensitive) {
|
||||
Command cmd = createCollection(name, query, caseInsensitive);
|
||||
addChild(cmd);
|
||||
return cmd;
|
||||
}
|
||||
public Command collection(String name, CollectionProvider provider, boolean caseInsensitive) {
|
||||
Command cmd = createCollection(name, provider, caseInsensitive);
|
||||
addChild(cmd);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
public static Command createCollection(String name, SimpleCollectionQuery query, boolean caseInsensitive) {
|
||||
return new Command(name, new CollectionArgParser(
|
||||
() -> query.get().stream().collect(Collectors.toMap(v->v, v->v)),
|
||||
caseInsensitive)
|
||||
);
|
||||
}
|
||||
public static Command createCollection(String name, CollectionProvider provider, boolean caseInsensitive) {
|
||||
return new Command(name, new CollectionArgParser(provider, caseInsensitive));
|
||||
}
|
||||
public static Command createPlayer(String name, boolean caseInsensitive) {
|
||||
return new Command(name, new PlayerArgParser(caseInsensitive));
|
||||
}
|
||||
public static Command createEnum(String name, Class<? extends Enum<?>> enumType, boolean caseInsensitive) {
|
||||
return new Command(name, new EnumArgParser(enumType, caseInsensitive));
|
||||
}
|
||||
public static Command createString(String name, boolean greedy) {
|
||||
return new Command(name, new StringArgParser(greedy));
|
||||
}
|
||||
public static Command createInt(String name) {
|
||||
return new Command(name, new IntArgParser());
|
||||
}
|
||||
public static Command createLocation(String name) {
|
||||
return new Command(name, new LocationArgParser());
|
||||
}
|
||||
public static Command createLiteral(String lit) {
|
||||
return new Command(lit, new LiteralArgParser(lit));
|
||||
}
|
||||
public static Command createLiteral(String lit, String ...aliases) {
|
||||
return new Command(lit, new LiteralArgParser(lit, aliases));
|
||||
}
|
||||
|
||||
public interface SimpleCollectionQuery {
|
||||
Collection<String> get();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package me.topchetoeu.bedwars.commandUtility;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public interface CommandExecutor {
|
||||
void execute(CommandSender sender, Command cmd, String alias, String[] args);
|
||||
String execute(CommandSender sender, Command cmd, Map<String, Object> args);
|
||||
}
|
||||
|
@ -1,62 +1,97 @@
|
||||
package me.topchetoeu.bedwars.commandUtility;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import me.topchetoeu.bedwars.commandUtility.args.LiteralArgParser;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class CommandExecutors {
|
||||
private static String join(String[] arr, String separator) {
|
||||
if (arr.length == 0) return "";
|
||||
if (arr.length == 1) return arr[0];
|
||||
// private static List<String> getSyntaxes(Command cmd) {
|
||||
// ArrayList<String> syntaxes = new ArrayList<>();
|
||||
|
||||
String res = arr[0];
|
||||
// for (Command child : cmd.getChildren()) {
|
||||
// ArgParser parser = child.getParser();
|
||||
|
||||
for (int i = 1; i < arr.length; i++) {
|
||||
res += separator + arr[i];
|
||||
// if (parser instanceof LiteralArgParser) {
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static CommandExecutor help() {
|
||||
return (sender, cmd, _args) -> {
|
||||
List<String> args = (List<String>)_args.get("args");
|
||||
if (args == null) args = new ArrayList<>();
|
||||
|
||||
String path = "/" + cmd.getName();
|
||||
Command currCmd = cmd;
|
||||
|
||||
while (args.size() > 0) {
|
||||
Command next = null;
|
||||
|
||||
for (Command child : currCmd.getChildren()) {
|
||||
if (child.getParser() instanceof LiteralArgParser && child.getParser().parse(sender, args).hasSucceeded()) {
|
||||
next = child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
if (next == null) break;
|
||||
|
||||
currCmd = next;
|
||||
path += " " + args.get(0);
|
||||
args.remove(0);
|
||||
}
|
||||
|
||||
public static CommandExecutor help(Command mainCmd) {
|
||||
return new CommandExecutor() {
|
||||
@Override
|
||||
public void execute(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
Command currCmd = mainCmd;
|
||||
String path = "/" + mainCmd.getName();
|
||||
cmd = currCmd;
|
||||
LiteralArgParser cmdParser = (LiteralArgParser)cmd.getParser();
|
||||
|
||||
for (String arg : args) {
|
||||
currCmd = currCmd.getAttachedCommand(arg);
|
||||
if (currCmd == null) {
|
||||
String msg = "Help can't be provided for the command.";
|
||||
sender.sendMessage(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
path += " " + currCmd.getName();
|
||||
}
|
||||
|
||||
sender.sendMessage(path + ": " + (currCmd.getHelpMessage() == null ?
|
||||
"no help provided" :
|
||||
currCmd.getHelpMessage())
|
||||
sender.spigot().sendMessage(new ComponentBuilder()
|
||||
.append("Help for %s: ".formatted(path))
|
||||
.bold(true)
|
||||
.create()
|
||||
);
|
||||
if (cmd.getHelpMessage() != null) sender.spigot().sendMessage(new ComponentBuilder()
|
||||
.append(" " + cmd.getHelpMessage())
|
||||
.create()
|
||||
);
|
||||
sender.spigot().sendMessage(new ComponentBuilder()
|
||||
.append(" Aliases: ")
|
||||
.bold(true)
|
||||
.append(String.join(", ", cmdParser.getAliases()))
|
||||
.bold(false)
|
||||
.create()
|
||||
);
|
||||
sender.spigot().sendMessage(new ComponentBuilder()
|
||||
.append(" Subcommands: ")
|
||||
.bold(true)
|
||||
.create()
|
||||
);
|
||||
if (currCmd.getAliases().length != 0)
|
||||
sender.sendMessage("Aliases: " + join(currCmd.getAliases(), ", "));
|
||||
|
||||
if (currCmd.getAttachedCommands().length > 0) {
|
||||
sender.sendMessage("Commands: ");
|
||||
for (Command subCmd : currCmd.getAttachedCommands()) {
|
||||
sender.sendMessage(path + " " + subCmd.getName() + ": " + subCmd.getHelpMessage());
|
||||
}
|
||||
for (Command child : currCmd.getChildren()) {
|
||||
if (child.getParser() instanceof LiteralArgParser) {
|
||||
sender.spigot().sendMessage(new ComponentBuilder()
|
||||
.append(" %s: ".formatted(((LiteralArgParser)child.getParser()).getLiteral()))
|
||||
.bold(true)
|
||||
.append(child.getHelpMessage() != null ? child.getHelpMessage() : "No help provided.")
|
||||
.bold(false)
|
||||
.create()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
public static CommandExecutor message(String msg) {
|
||||
return new CommandExecutor() {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
return (sender, cmd, args) -> {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public interface ArgParser {
|
||||
ArgParserRes parse(CommandSender sender, List<String> remainingArgs);
|
||||
void addCompleteSuggestions(CommandSender sender, List<String> args, Suggestions suggestions);
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
public class ArgParserRes {
|
||||
private int takenCount;
|
||||
private Object res;
|
||||
private boolean failed;
|
||||
private String error;
|
||||
|
||||
public int getTakenCount() {
|
||||
return takenCount;
|
||||
}
|
||||
public Object getResult() {
|
||||
return res;
|
||||
}
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
public boolean takenAny() {
|
||||
return takenCount > 0;
|
||||
}
|
||||
public boolean hasResult() {
|
||||
return res != null;
|
||||
}
|
||||
public boolean hasFailed() {
|
||||
return failed;
|
||||
}
|
||||
public boolean hasSucceeded() {
|
||||
return !failed;
|
||||
}
|
||||
public boolean hasError() {
|
||||
return error != null && !error.isEmpty();
|
||||
}
|
||||
|
||||
private ArgParserRes(int takenCount, Object res, String error, boolean failed) {
|
||||
this.takenCount = takenCount;
|
||||
this.res = res;
|
||||
this.failed = failed;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public static ArgParserRes error(String error) {
|
||||
if (error == null || error.isEmpty()) error = "An error ocurred while paring the arguments";
|
||||
|
||||
return new ArgParserRes(0, null, error, true);
|
||||
}
|
||||
|
||||
public static ArgParserRes fail() {
|
||||
return new ArgParserRes(0, null, null, true);
|
||||
}
|
||||
|
||||
public static ArgParserRes takenNone() {
|
||||
return takenNone(null);
|
||||
}
|
||||
public static ArgParserRes takenOne() {
|
||||
return takenOne(null);
|
||||
}
|
||||
public static ArgParserRes takenMany(int count) {
|
||||
return takenMany(count, null);
|
||||
}
|
||||
|
||||
public static ArgParserRes takenNone(Object res) {
|
||||
return new ArgParserRes(0, res, null, false);
|
||||
}
|
||||
public static ArgParserRes takenOne(Object res) {
|
||||
return new ArgParserRes(1, res, null, false);
|
||||
}
|
||||
public static ArgParserRes takenMany(int count, Object res) {
|
||||
if (count < 1) return takenNone(res);
|
||||
return new ArgParserRes(count, res, null, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CollectionArgParser implements ArgParser {
|
||||
private final boolean caseInsensitive;
|
||||
private final CollectionProvider provider;
|
||||
|
||||
public boolean isCaseInsensitive() {
|
||||
return caseInsensitive;
|
||||
}
|
||||
public boolean isCaseSensitive() {
|
||||
return !caseInsensitive;
|
||||
}
|
||||
|
||||
public CollectionProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgParserRes parse(CommandSender sender, List<String> remainingArgs) {
|
||||
String arg = remainingArgs.get(0);
|
||||
Map<String, Object> map = provider.get();
|
||||
if (caseInsensitive) arg = arg.toLowerCase();
|
||||
if (map.containsKey(arg)) return ArgParserRes.takenOne(map.get(arg));
|
||||
else return ArgParserRes.error("Unknown element '" + arg + "'.");
|
||||
}
|
||||
|
||||
public CollectionArgParser addElement(String element, Object parsesTo) {
|
||||
if (caseInsensitive) element = element.toLowerCase();
|
||||
Map<String, Object> map = provider.get();
|
||||
map.put(element, parsesTo);
|
||||
return this;
|
||||
}
|
||||
public CollectionArgParser addElements(Map<String, Object> parseTable) {
|
||||
for (Map.Entry<String, Object> a : parseTable.entrySet()) {
|
||||
if (caseInsensitive) addElement(a.getKey().toLowerCase(), a.getValue());
|
||||
else addElement(a.getKey(), a.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCompleteSuggestions(CommandSender sender, List<String> args, Suggestions suggestions) {
|
||||
String arg;
|
||||
if (caseInsensitive) arg = args.get(0).toLowerCase();
|
||||
else arg = args.get(0);
|
||||
Map<String, Object> map = provider.get();
|
||||
List<String> _suggestions = map.keySet().stream().filter(v -> v.startsWith(arg)).toList();
|
||||
suggestions.addSuggestions(_suggestions);
|
||||
if (_suggestions.size() == 0) suggestions.error("Unknown element '" + arg + "'.");
|
||||
}
|
||||
|
||||
public CollectionArgParser(CollectionProvider provider, boolean caseInsensitive) {
|
||||
this.provider = provider;
|
||||
this.caseInsensitive = caseInsensitive;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface CollectionProvider {
|
||||
Map<String, Object> get();
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
public class EnumArgParser extends StaticCollectionArgParser {
|
||||
|
||||
private static Map<String, Object> getCol(Class<? extends Enum<?>> enumType, boolean caseInsensitive) {
|
||||
Map<String, Object> map = new Hashtable<>();
|
||||
if (enumType.getEnumConstants() != null) {
|
||||
for (Enum<?> c : enumType.getEnumConstants()) {
|
||||
if (caseInsensitive) map.put(c.name().toLowerCase(), c);
|
||||
else map.put(c.name(), c);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public EnumArgParser(Class<? extends Enum<?>> enumType, boolean caseInsensitive) {
|
||||
super(getCol(enumType, caseInsensitive), caseInsensitive);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class IntArgParser implements ArgParser {
|
||||
@Override
|
||||
public ArgParserRes parse(CommandSender sender, List<String> remainingArgs) {
|
||||
try {
|
||||
return ArgParserRes.takenOne(Integer.parseInt(remainingArgs.get(0)));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return ArgParserRes.error("Invalid number format.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCompleteSuggestions(CommandSender sender, List<String> args, Suggestions suggestions) {
|
||||
suggestions.addSuggestion("0");
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class LiteralArgParser implements ArgParser {
|
||||
private final String literal;
|
||||
private final List<String> aliases = new ArrayList<>();
|
||||
|
||||
public String getLiteral() {
|
||||
return literal;
|
||||
}
|
||||
public List<String> getAliases() {
|
||||
return Collections.unmodifiableList(aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgParserRes parse(CommandSender sender, List<String> remainingArgs) {
|
||||
if (!remainingArgs.get(0).equals(literal) && !aliases.contains(remainingArgs.get(0))) return ArgParserRes.fail();
|
||||
else return ArgParserRes.takenOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCompleteSuggestions(CommandSender sender, List<String> args, Suggestions elements) {
|
||||
String arg = args.get(0);
|
||||
|
||||
elements.addSuggestions(aliases.stream().filter(v -> v.startsWith(arg)));
|
||||
if (literal.startsWith(arg)) elements.addSuggestion(literal);
|
||||
}
|
||||
|
||||
public LiteralArgParser(String lit) {
|
||||
this.literal = lit;
|
||||
}
|
||||
public LiteralArgParser(String lit, String ...aliases) {
|
||||
this.literal = lit;
|
||||
Collections.addAll(this.aliases, aliases);
|
||||
}
|
||||
public LiteralArgParser(String lit, Collection<String> aliases) {
|
||||
this.literal = lit;
|
||||
this.aliases.addAll(aliases);
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
public class LocationArgParser implements ArgParser {
|
||||
|
||||
@Override
|
||||
public ArgParserRes parse(CommandSender sender, List<String> remainingArgs) {
|
||||
if (remainingArgs.size() < 3) return ArgParserRes.fail();
|
||||
else {
|
||||
Location loc = null;
|
||||
if (sender instanceof LivingEntity) loc = ((LivingEntity)sender).getLocation();
|
||||
else if (sender instanceof BlockCommandSender) loc = ((BlockCommandSender)sender).getBlock().getLocation();
|
||||
else return ArgParserRes.error("Coordinates may not be specified by a non-located command sender.");
|
||||
|
||||
String rawX = remainingArgs.get(0),
|
||||
rawY = remainingArgs.get(1),
|
||||
rawZ = remainingArgs.get(2);
|
||||
|
||||
boolean relX = false, relY = false, relZ = false;
|
||||
|
||||
if (rawX.startsWith("~")) {
|
||||
relX = true;
|
||||
rawX = rawX.substring(1);
|
||||
if (rawX.isEmpty()) rawX = "0";
|
||||
}
|
||||
if (rawY.startsWith("~")) {
|
||||
relY = true;
|
||||
rawY = rawY.substring(1);
|
||||
if (rawY.isEmpty()) rawY = "0";
|
||||
}
|
||||
if (rawZ.startsWith("~")) {
|
||||
relZ = true;
|
||||
rawZ = rawZ.substring(1);
|
||||
if (rawZ.isEmpty()) rawZ = "0";
|
||||
}
|
||||
|
||||
double x, y, z;
|
||||
|
||||
try {
|
||||
x = Double.parseDouble(rawX);
|
||||
y = Double.parseDouble(rawY);
|
||||
z = Double.parseDouble(rawZ);
|
||||
} catch(NumberFormatException e) {
|
||||
return ArgParserRes.error("Invalid number format.");
|
||||
}
|
||||
|
||||
if (relX) x += loc.getX();
|
||||
if (relY) y += loc.getY();
|
||||
if (relZ) z += loc.getZ();
|
||||
|
||||
return ArgParserRes.takenMany(3, new Location(loc.getWorld(), x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
private void addSuggestions(String arg, Double curr, Suggestions suggestions) {
|
||||
if (arg.isEmpty()) {
|
||||
suggestions.addSuggestions("~", curr.toString(), Double.toString(Math.floor(curr)), Double.toString(Math.floor(curr) + 0.5));
|
||||
}
|
||||
else if (arg.startsWith("~")) {
|
||||
arg = arg.substring(1);
|
||||
|
||||
suggestions.addSuggestions("~" + arg, "~" + ".5");
|
||||
}
|
||||
else suggestions.addSuggestion(arg);
|
||||
|
||||
if (arg.length() > 0) {
|
||||
try {
|
||||
Double.parseDouble(arg);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
suggestions.error("Number is in an invalid format.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCompleteSuggestions(CommandSender sender, List<String> args, Suggestions suggestions) {
|
||||
Location loc = null;
|
||||
if (sender instanceof LivingEntity) loc = ((LivingEntity)sender).getLocation();
|
||||
else if (sender instanceof BlockCommandSender) loc = ((BlockCommandSender)sender).getBlock().getLocation();
|
||||
else {
|
||||
suggestions.error("Only located command senders may use locations.");
|
||||
return;
|
||||
}
|
||||
|
||||
double curr = loc.getZ();
|
||||
if (args.size() < 3) curr = loc.getY();
|
||||
if (args.size() < 2) curr = loc.getX();
|
||||
|
||||
String arg = args.get(args.size() - 1);
|
||||
addSuggestions(arg, curr, suggestions);
|
||||
}
|
||||
|
||||
public LocationArgParser() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerArgParser extends CollectionArgParser {
|
||||
|
||||
public PlayerArgParser(boolean caseInsensitive) {
|
||||
super(() -> Bukkit.getOnlinePlayers().stream().collect(Collectors.toMap(Player::getName, v->v)), caseInsensitive);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class StaticCollectionArgParser extends CollectionArgParser {
|
||||
private Map<String, Object> map;
|
||||
|
||||
public Map<String, Object> getMap() {
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
public StaticCollectionArgParser(Map<String, Object> map, boolean caseInsensitive) {
|
||||
super(() -> map, caseInsensitive);
|
||||
this.map = map;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class StringArgParser implements ArgParser {
|
||||
private final boolean greeedy;
|
||||
|
||||
public boolean isGreedy() {
|
||||
return greeedy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgParserRes parse(CommandSender sender, List<String> remainingArgs) {
|
||||
if (greeedy) return ArgParserRes.takenMany(remainingArgs.size(), String.join(" ", remainingArgs));
|
||||
else return ArgParserRes.takenOne(remainingArgs.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCompleteSuggestions(CommandSender sender, List<String> args, Suggestions suggestions) {
|
||||
}
|
||||
|
||||
public StringArgParser(boolean greedy) {
|
||||
greeedy = greedy;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package me.topchetoeu.bedwars.commandUtility.args;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Suggestions {
|
||||
private final List<String> suggestions = new ArrayList<>();
|
||||
private String error = null;
|
||||
|
||||
public boolean addSuggestion(String suggestion) {
|
||||
return suggestions.add(suggestion);
|
||||
}
|
||||
public void addSuggestions(Collection<String> suggestions) {
|
||||
for (String suggestion : suggestions) addSuggestion(suggestion);
|
||||
}
|
||||
public void addSuggestions(String ...suggestions) {
|
||||
Collections.addAll(this.suggestions, suggestions);
|
||||
}
|
||||
public void addSuggestions(Stream<String> suggestions) {
|
||||
this.suggestions.addAll(suggestions.toList());
|
||||
}
|
||||
public boolean hasSuggestion(String suggestion) {
|
||||
return suggestions.contains(suggestion);
|
||||
}
|
||||
public List<String> getSuggestions() {
|
||||
return Collections.unmodifiableList(suggestions);
|
||||
}
|
||||
|
||||
public void error(String error) {
|
||||
if (error == null || error.trim().isEmpty()) return;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public boolean hasError() {
|
||||
return error != null;
|
||||
}
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public Suggestions(List<String> suggestions) {
|
||||
this.suggestions.addAll(suggestions);
|
||||
}
|
||||
public Suggestions() {
|
||||
}
|
||||
}
|
Binary file not shown.
@ -6,7 +6,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
@ -18,9 +17,9 @@ public class Config {
|
||||
|
||||
private int perTeam = 0;
|
||||
private Location respawnLocation;
|
||||
private ArrayList<TeamColor> colors;
|
||||
private ArrayList<Location> diamondGenerators;
|
||||
private ArrayList<Location> emeraldGenerators;
|
||||
private List<TeamColor> colors;
|
||||
private List<Location> diamondGenerators;
|
||||
private List<Location> emeraldGenerators;
|
||||
|
||||
public Location getRespawnLocation() {
|
||||
return respawnLocation;
|
||||
@ -36,18 +35,18 @@ public class Config {
|
||||
perTeam = size;
|
||||
}
|
||||
|
||||
public ArrayList<TeamColor> getColors() {
|
||||
public List<TeamColor> getColors() {
|
||||
return colors;
|
||||
}
|
||||
public TeamColor getColor(String name) {
|
||||
return Config.instance.getColors()
|
||||
return getColors()
|
||||
.stream()
|
||||
.filter(v -> v.getName().equals(name.toLowerCase()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public ArrayList<Location> getDiamondGenerators() {
|
||||
public List<Location> getDiamondGenerators() {
|
||||
return diamondGenerators;
|
||||
}
|
||||
public Location getClosestDiamondGenerator(Location loc) {
|
||||
@ -72,7 +71,7 @@ public class Config {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ArrayList<Location> getEmeraldGenerators() {
|
||||
public List<Location> getEmeraldGenerators() {
|
||||
return emeraldGenerators;
|
||||
}
|
||||
public Location getClosestEmeraldGenerator(Location loc) {
|
||||
@ -97,10 +96,6 @@ public class Config {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static ArrayList<?> toList(Stream<?> s) {
|
||||
return new ArrayList<>(s.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void load(File confFile) {
|
||||
Configuration conf = YamlConfiguration.loadConfiguration(confFile);
|
||||
@ -109,21 +104,22 @@ public class Config {
|
||||
|
||||
c.perTeam = conf.getInt("perTeam");
|
||||
if (conf.get("respawnLocation") != null) c.respawnLocation = Location.deserialize(conf.getConfigurationSection("respawnLocation").getValues(false));
|
||||
c.colors = (ArrayList<TeamColor>)toList(conf
|
||||
c.colors = new ArrayList<>(conf
|
||||
.getMapList("colors")
|
||||
.stream()
|
||||
.map(v -> TeamColor.deserialize((Map<String, Object>)v))
|
||||
);
|
||||
c.diamondGenerators = (ArrayList<Location>)toList(conf
|
||||
.toList());
|
||||
c.diamondGenerators = new ArrayList<>(conf
|
||||
.getMapList("diamondGenerators")
|
||||
.stream()
|
||||
.map(v -> Location.deserialize((Map<String, Object>)v))
|
||||
);
|
||||
c.emeraldGenerators = (ArrayList<Location>)toList(conf
|
||||
.toList())
|
||||
;
|
||||
c.emeraldGenerators = new ArrayList<>(conf
|
||||
.getMapList("emeraldGenerators")
|
||||
.stream()
|
||||
.map(v -> Location.deserialize((Map<String, Object>)v))
|
||||
);
|
||||
.toList());
|
||||
|
||||
instance = c;
|
||||
}
|
||||
@ -132,9 +128,9 @@ public class Config {
|
||||
FileConfiguration conf = YamlConfiguration.loadConfiguration(confFile);
|
||||
|
||||
conf.set("perTeam", perTeam);
|
||||
conf.set("colors", toList(colors.stream().map(v -> v.serialize())));
|
||||
conf.set("diamondGenerators", toList(diamondGenerators.stream().map(v -> v.serialize())));
|
||||
conf.set("emeraldGenerators", toList(emeraldGenerators.stream().map(v -> v.serialize())));
|
||||
conf.set("colors", colors.stream().map(v -> v.serialize()).toList());
|
||||
conf.set("diamondGenerators", diamondGenerators.stream().map(v -> v.serialize()).toList());
|
||||
conf.set("emeraldGenerators", emeraldGenerators.stream().map(v -> v.serialize()).toList());
|
||||
|
||||
try {
|
||||
conf.save(confFile);
|
||||
|
@ -76,8 +76,8 @@ public class Game implements Listener, AutoCloseable {
|
||||
ScoreboardManager.updateAll();
|
||||
}
|
||||
|
||||
public static void stop(boolean immediatly) {
|
||||
if (immediatly) stop();
|
||||
public static void stop(boolean immediately) {
|
||||
if (immediately) stop();
|
||||
else Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> stop(), 20 * 5);
|
||||
}
|
||||
public static boolean isStarted() {
|
||||
@ -102,7 +102,7 @@ public class Game implements Listener, AutoCloseable {
|
||||
|
||||
public void win(TeamColor color) {
|
||||
getTeam(color).sendTitle("You won!", "", 0, 20 * 5, 0);
|
||||
getTeam(color).sendTilteToOthers(color.getColorName() + " won!", "You lost :(", 0, 20 * 5, 0);
|
||||
getTeam(color).sendTitleToOthers(color.getColorName() + " won!", "You lost :(", 0, 20 * 5, 0);
|
||||
stop(false);
|
||||
}
|
||||
|
||||
@ -386,7 +386,7 @@ public class Game implements Listener, AutoCloseable {
|
||||
spectators.add(removed);
|
||||
if (removed.isOnline()) {
|
||||
removed.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
removed.getPlayer().teleport(Config.instance.getRespawnLocation());
|
||||
removed.getPlayer().teleport(new Location(removed.getPlayer().getLocation().getWorld(), 0, 80, 0));
|
||||
}
|
||||
if (removed.isOnline()) removed.getPlayer().sendMessage("You will be a spectator");
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public class ScoreboardManager {
|
||||
private static Hashtable<UUID, Scoreboard> scoreboards = new Hashtable<>();
|
||||
|
||||
@ -25,7 +27,7 @@ public class ScoreboardManager {
|
||||
if (v.getRemainingPlayers() == 0) teamCounter = "§4✖";
|
||||
else if (!v.hasBed()) teamCounter = Integer.toString(v.getRemainingPlayers());
|
||||
|
||||
String newStr = String.format(" %s§r: %s", v.getTeamColor().getColorName(), teamCounter);
|
||||
String newStr = String.format(" %s§r: %s", BaseComponent.toLegacyText(v.getTeamColor().getColorName()), teamCounter);
|
||||
|
||||
if (v.hasPlayer(p)) {
|
||||
newStr = (newStr + "§r (you)").replaceAll("§([0-9a-z])", "§$1§l");
|
||||
|
@ -27,6 +27,7 @@ import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import me.topchetoeu.bedwars.Main;
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import me.topchetoeu.bedwars.engine.trader.upgrades.TeamUpgrade;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class Team implements Listener, AutoCloseable {
|
||||
private TeamColor color;
|
||||
@ -66,10 +67,10 @@ public class Team implements Listener, AutoCloseable {
|
||||
if (bwp.isOnline()) {
|
||||
Player p = bwp.getOnlinePlayer();
|
||||
|
||||
String msg = color.getColorName() + "§r's bed was destroyed";
|
||||
if (player != null) msg += " by " + player.getName();
|
||||
msg += ".";
|
||||
Bukkit.broadcastMessage(msg);
|
||||
ComponentBuilder cb = new ComponentBuilder().append(color.getColorName()).append("'s bed was destroyed").reset();
|
||||
if (player != null) cb.append(" by " + player.getName());
|
||||
cb.append(".");
|
||||
Bukkit.spigot().broadcast(cb.create());
|
||||
|
||||
Utility.sendTitle(p, "Bed destroyed!", "You will no longer respawn!", 5, 35, 10);
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1, 1);
|
||||
@ -204,7 +205,7 @@ public class Team implements Listener, AutoCloseable {
|
||||
if (bwp.isOnline()) Utility.sendTitle(bwp.getOnlinePlayer(), title, subtitle, fadein, duration, fadeout);
|
||||
}
|
||||
}
|
||||
public void sendTilteToOthers(String title, String subtitle, int fadein, int duration, int fadeout) {
|
||||
public void sendTitleToOthers(String title, String subtitle, int fadein, int duration, int fadeout) {
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (players.stream().noneMatch(v -> v.getPlayer().getUniqueId().equals(p.getUniqueId())))
|
||||
Utility.sendTitle(p, title, subtitle, fadein, duration, fadeout);
|
||||
|
@ -8,10 +8,15 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class TeamColor implements ConfigurationSerializable {
|
||||
private String name;
|
||||
private Material wool;
|
||||
private char chatColor;
|
||||
private ChatColor chatColor;
|
||||
private Color color;
|
||||
private Location bed = null;
|
||||
private Location spawnLocation = null;
|
||||
@ -20,8 +25,8 @@ public class TeamColor implements ConfigurationSerializable {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getColorName() {
|
||||
return String.format("§%c%s%s", chatColor, name.substring(0, 1).toUpperCase(), name.substring(1));
|
||||
public BaseComponent[] getColorName() {
|
||||
return new ComponentBuilder().append(name).color(chatColor).create();
|
||||
}
|
||||
public Material getWoolMaterial() {
|
||||
return wool;
|
||||
@ -29,7 +34,7 @@ public class TeamColor implements ConfigurationSerializable {
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
public char getChatColor() {
|
||||
public ChatColor getChatColor() {
|
||||
return chatColor;
|
||||
}
|
||||
|
||||
@ -58,7 +63,7 @@ public class TeamColor implements ConfigurationSerializable {
|
||||
return bed != null && spawnLocation != null && generatorLocation != null;
|
||||
}
|
||||
|
||||
public TeamColor(String name, Material wool, Color color, char colorId) {
|
||||
public TeamColor(String name, Material wool, Color color, ChatColor colorId) {
|
||||
this.name = name;
|
||||
this.wool = wool;
|
||||
this.color = color;
|
||||
@ -69,9 +74,9 @@ public class TeamColor implements ConfigurationSerializable {
|
||||
Map<String, Object> map = new Hashtable<>();
|
||||
|
||||
map.put("name", name);
|
||||
map.put("wool", wool.getKey().toString());
|
||||
map.put("wool", wool.getKey().getKey().toLowerCase());
|
||||
map.put("color", color.serialize());
|
||||
map.put("chatColor", chatColor);
|
||||
map.put("chatColor", chatColor.getName());
|
||||
|
||||
if (bed != null) map.put("bed", bed.serialize());
|
||||
if (generatorLocation != null) map.put("generator", generatorLocation.serialize());
|
||||
@ -79,13 +84,13 @@ public class TeamColor implements ConfigurationSerializable {
|
||||
|
||||
return map;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public static TeamColor deserialize(Map<String, Object> map) {
|
||||
TeamColor color = new TeamColor(
|
||||
(String)map.get("name"),
|
||||
map.get("name").toString(),
|
||||
Material.getMaterial(map.get("wool").toString().toUpperCase()),
|
||||
Color.deserialize((Map<String, Object>)map.get("color")),
|
||||
map.get("chatColor").toString().charAt(0)
|
||||
Utility.bukkitToBungeeColor(org.bukkit.ChatColor.valueOf(map.get("chatColor").toString().toUpperCase()))
|
||||
);
|
||||
|
||||
if (map.containsKey("bed")) color.setBedLocation(Location.deserialize((Map<String, Object>) map.get("bed")));
|
||||
|
@ -4,9 +4,11 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public interface Deal {
|
||||
public ItemStack getDealItem(Player p);
|
||||
public String getDealName(Player p);
|
||||
public BaseComponent[] getDealName(Player p);
|
||||
public Material getPriceType(Player p);
|
||||
public int getPrice(Player p);
|
||||
public boolean alreadyBought(Player p);
|
||||
|
@ -23,6 +23,9 @@ import me.topchetoeu.bedwars.InventoryUtility;
|
||||
import me.topchetoeu.bedwars.Main;
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import me.topchetoeu.bedwars.engine.trader.dealTypes.ItemDeal;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
// Very bad code.
|
||||
public class TraderGUI implements Listener {
|
||||
@ -43,11 +46,11 @@ public class TraderGUI implements Listener {
|
||||
}
|
||||
|
||||
public ItemStack generateDealItem(Deal d, boolean addFavouriteLore) {
|
||||
String name = "§r" + d.getDealName(player);
|
||||
String name = "§r" + BaseComponent.toLegacyText(d.getDealName(player));
|
||||
if (d.alreadyBought(player)) name += " §4(already unlocked)";
|
||||
else name += String.format(" (%dx %s)",
|
||||
d.getPrice(player),
|
||||
Utility.getItemName(d.getPriceType(player))
|
||||
BaseComponent.toLegacyText(Utility.getItemName(d.getPriceType(player)))
|
||||
);
|
||||
|
||||
ItemStack item = Utility.copyNamedItem(d.getDealItem(player), name);
|
||||
@ -170,6 +173,7 @@ public class TraderGUI implements Listener {
|
||||
|
||||
player.getInventory().setContents(inv);
|
||||
|
||||
player.spigot().sendMessage(new ComponentBuilder().append("You just purchased ").append(deal.getDealName(player)).create());
|
||||
deal.commence(player);
|
||||
updateSection();
|
||||
if (player.getInventory().contains(Material.STONE_SWORD) ||
|
||||
@ -182,7 +186,12 @@ public class TraderGUI implements Listener {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_YES, 1, 1);
|
||||
}
|
||||
else {
|
||||
player.sendMessage(String.format("You don't have enough %ss!", Utility.getItemName(deal.getPriceType(player)).toLowerCase()));
|
||||
player.spigot().sendMessage(new ComponentBuilder()
|
||||
.append("You don't have enough ")
|
||||
.append(Utility.getItemName(deal.getPriceType(player)))
|
||||
.append(new TextComponent("!"))
|
||||
.create()
|
||||
);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
|
||||
}
|
||||
}
|
||||
@ -331,7 +340,7 @@ public class TraderGUI implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public TraderGUI(File favsDir, Player p) {
|
||||
public TraderGUI(File favouritesDir, Player p) {
|
||||
this.sections = Sections.getSections();
|
||||
this.player = p;
|
||||
Bukkit.getPluginManager().registerEvents(this, Main.getInstance());
|
||||
|
@ -29,6 +29,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.topchetoeu.bedwars.Main;
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
|
||||
public class Traders implements Listener {
|
||||
public static Traders instance = null;
|
||||
@ -36,6 +37,8 @@ public class Traders implements Listener {
|
||||
private List<UUID> villagers = new ArrayList<>();
|
||||
private File file;
|
||||
|
||||
private final ItemStack eradicator, spawner;
|
||||
|
||||
private void write() {
|
||||
try {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file));
|
||||
@ -49,6 +52,10 @@ public class Traders implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public void give(Player p) {
|
||||
p.getInventory().addItem(eradicator, spawner);
|
||||
}
|
||||
|
||||
public Villager summonVillager(Location loc) {
|
||||
Villager vil = (Villager)loc.getWorld().spawnEntity(loc, EntityType.VILLAGER);
|
||||
|
||||
@ -78,9 +85,7 @@ public class Traders implements Listener {
|
||||
private void onUse(PlayerInteractEvent e) {
|
||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
||||
e.hasItem() &&
|
||||
e.getItem().hasItemMeta() &&
|
||||
e.getItem().getItemMeta().hasDisplayName() &&
|
||||
e.getItem().getItemMeta().getDisplayName() == "§rTrader spawner") {
|
||||
spawner.getItemMeta().equals(e.getItem().getItemMeta())) {
|
||||
if (e.getItem().getType() == Material.VILLAGER_SPAWN_EGG) {
|
||||
int yaw = (int)e.getPlayer().getLocation().getYaw() - 45;
|
||||
if (yaw < 0) yaw += 360;
|
||||
@ -108,6 +113,8 @@ public class Traders implements Listener {
|
||||
|
||||
e.getPlayer().sendMessage("Trader spawned!");
|
||||
e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_YES, 1, 1);
|
||||
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,8 +143,7 @@ public class Traders implements Listener {
|
||||
|
||||
if (hand != null &&
|
||||
hand.hasItemMeta() &&
|
||||
hand.getItemMeta().hasDisplayName() &&
|
||||
hand.getItemMeta().getDisplayName().equals("§rTrader eradicator")) {
|
||||
eradicator.getItemMeta().equals(hand.getItemMeta())) {
|
||||
if (hand.getType() == Material.STICK) {
|
||||
villagers.remove(v.getUniqueId());
|
||||
write();
|
||||
@ -162,6 +168,9 @@ public class Traders implements Listener {
|
||||
|
||||
file = tradersFile;
|
||||
|
||||
spawner = Utility.namedItem(new ItemStack(Material.VILLAGER_SPAWN_EGG), "§rTrader spawner");
|
||||
eradicator = Utility.namedItem(new ItemStack(Material.STICK), "§rTrader eradicator");
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, Main.getInstance());
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
package me.topchetoeu.bedwars.engine.trader.dealTypes;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.topchetoeu.bedwars.engine.Game;
|
||||
import me.topchetoeu.bedwars.engine.trader.Deal;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class EnforcedRankedDeal implements Deal {
|
||||
private Rank soldRank;
|
||||
@ -24,8 +25,8 @@ public class EnforcedRankedDeal implements Deal {
|
||||
return icon;
|
||||
}
|
||||
@Override
|
||||
public String getDealName(Player p) {
|
||||
return soldRank.getNextTier(p).getDisplayName();
|
||||
public BaseComponent[] getDealName(Player p) {
|
||||
return new ComponentBuilder().append(soldRank.getNextTier(p).getDisplayName()).reset().create();
|
||||
}
|
||||
@Override
|
||||
public Material getPriceType(Player p) {
|
||||
@ -41,7 +42,6 @@ public class EnforcedRankedDeal implements Deal {
|
||||
}
|
||||
@Override
|
||||
public void commence(Player p) {
|
||||
p.sendMessage(String.format("§rYou just purchased %s.", getDealName(p)));
|
||||
soldRank.increasePlayerTier(p, soldRank.getNextTier(p));
|
||||
}
|
||||
|
||||
|
@ -13,10 +13,6 @@ import me.topchetoeu.bedwars.engine.trader.Deal;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.minecraft.EnumChatFormat;
|
||||
import net.minecraft.network.chat.ChatBaseComponent;
|
||||
import net.minecraft.network.chat.ChatComponentText;
|
||||
import net.minecraft.network.chat.IChatBaseComponent;
|
||||
|
||||
public class ItemDeal implements Deal {
|
||||
private ItemStack item;
|
||||
@ -32,11 +28,14 @@ public class ItemDeal implements Deal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatBaseComponent getDealName(Player p) {
|
||||
// BaseComponent.
|
||||
// new ComponentBuilder().color(ChatColor.WHITE).append(Integer.toString(item.getAmount())).append( Utility.getItemName(item));
|
||||
// String.format("§r%dx %s%s", item.getAmount(), Utility.getItemName(item), implemented ? "" : " §4§l(not implemented)§r");
|
||||
return new ChatComponentText("none lol");
|
||||
public BaseComponent[] getDealName(Player p) {
|
||||
ComponentBuilder builder = new ComponentBuilder()
|
||||
.append(Integer.toString(item.getAmount()))
|
||||
.color(ChatColor.WHITE)
|
||||
.append("x ")
|
||||
.append(Utility.getItemName(item));
|
||||
if (!implemented) builder.append(" (not implemented)").bold(true).color(ChatColor.RED);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,7 +58,6 @@ public class ItemDeal implements Deal {
|
||||
return;
|
||||
}
|
||||
ItemStack item = getDealItem(p);
|
||||
p.sendMessage(String.format("You just purchased %s.", getDealName(p)));
|
||||
ItemStack[] contents = p.getInventory().getContents();
|
||||
InventoryUtility.giveItem(contents, item);
|
||||
p.getInventory().setContents(contents);
|
||||
|
@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class RankTier {
|
||||
private String name;
|
||||
@ -17,8 +19,8 @@ public class RankTier {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getDisplayName() {
|
||||
return Utility.getItemName(icon);
|
||||
public BaseComponent[] getDisplayName() {
|
||||
return new ComponentBuilder().append(Utility.getItemName(icon)).reset().create();
|
||||
}
|
||||
public ItemStack getIcon() {
|
||||
return icon;
|
||||
|
@ -7,6 +7,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import me.topchetoeu.bedwars.engine.Game;
|
||||
import me.topchetoeu.bedwars.engine.trader.Deal;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class RankedDeal implements Deal {
|
||||
private Rank soldRank;
|
||||
@ -29,8 +31,8 @@ public class RankedDeal implements Deal {
|
||||
return icon;
|
||||
}
|
||||
@Override
|
||||
public String getDealName(Player p) {
|
||||
return Utility.getItemName(soldTier.getIcon());
|
||||
public BaseComponent[] getDealName(Player p) {
|
||||
return new ComponentBuilder().append(Utility.getItemName(soldTier.getIcon())).reset().create();
|
||||
}
|
||||
@Override
|
||||
public Material getPriceType(Player p) {
|
||||
@ -46,7 +48,6 @@ public class RankedDeal implements Deal {
|
||||
}
|
||||
@Override
|
||||
public void commence(Player p) {
|
||||
p.sendMessage(String.format("§rYou just purchased %s.", getDealName(p)));
|
||||
soldRank.increasePlayerTier(p, soldTier);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,9 @@ import me.topchetoeu.bedwars.engine.Game;
|
||||
import me.topchetoeu.bedwars.engine.Team;
|
||||
import me.topchetoeu.bedwars.engine.trader.Deal;
|
||||
import me.topchetoeu.bedwars.engine.trader.upgrades.TeamUpgrade;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class RankedUpgradeDeal implements Deal {
|
||||
private TeamUpgradeRank rank;
|
||||
@ -43,12 +46,12 @@ public class RankedUpgradeDeal implements Deal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDealName(Player p) {
|
||||
if (!Game.isStarted()) return "None";
|
||||
public BaseComponent[] getDealName(Player p) {
|
||||
if (!Game.isStarted()) return new BaseComponent[] { new TextComponent("???") };
|
||||
Team t = Game.instance.getTeam(p);
|
||||
if (t == null) return "None";
|
||||
if (t == null) return new BaseComponent[] { new TextComponent("???") };
|
||||
|
||||
return rank.getNextTeamUpgrade(t).getDisplayName();
|
||||
return new ComponentBuilder().reset().append(rank.getNextTeamUpgrade(t).getDisplayName()).create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +68,6 @@ public class SharpnessTeamUpgrade implements TeamUpgrade {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO Auto-generated method stub
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
10
src/plugin.yml
Normal file
10
src/plugin.yml
Normal file
@ -0,0 +1,10 @@
|
||||
name: bedwars-plugin
|
||||
version: 0.7.0
|
||||
description: A plugin that enables you to make a bedwars game
|
||||
authors: [ TopchetoEU, SpaceHQ ]
|
||||
main: me.topchetoeu.bedwars.Main
|
||||
api-version: 1.18
|
||||
commands:
|
||||
bedwars:
|
||||
description: A command used to control the bedwars plugin
|
||||
aliases: [ bw, bedwar ]
|
Loading…
Reference in New Issue
Block a user