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>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>minecraft-libraries</id>
|
||||||
|
<name>Minecraft Libraries</name>
|
||||||
|
<url>https://libraries.minecraft.net</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
@ -44,6 +52,11 @@
|
|||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${basedir}/deps/datafixerupper.jar</systemPath>
|
<systemPath>${basedir}/deps/datafixerupper.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mojang</groupId>
|
||||||
|
<artifactId>brigadier</artifactId>
|
||||||
|
<version>1.0.18</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -87,5 +100,13 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</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.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import me.topchetoeu.bedwars.commandUtility.Command;
|
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.BedwarsPlayer;
|
||||||
import me.topchetoeu.bedwars.engine.Config;
|
import me.topchetoeu.bedwars.engine.Config;
|
||||||
import me.topchetoeu.bedwars.engine.Game;
|
import me.topchetoeu.bedwars.engine.Game;
|
||||||
import me.topchetoeu.bedwars.engine.Team;
|
import me.topchetoeu.bedwars.engine.Team;
|
||||||
import me.topchetoeu.bedwars.engine.TeamColor;
|
import me.topchetoeu.bedwars.engine.TeamColor;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
|
||||||
public class Commands {
|
public class Commands {
|
||||||
private static File confFile = new File(Main.getInstance().getDataFolder(), "config.yml");
|
private static File confFile = new File(Main.getInstance().getDataFolder(), "config.yml");
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("unchecked")
|
||||||
public static CommandExecutor kill = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
public static Command kill(Command cmd) {
|
||||||
|
return cmd.player("players", false).setRecursive(true).setExecutor((sender, _cmd, args) -> {
|
||||||
if (Game.isStarted()) {
|
if (Game.isStarted()) {
|
||||||
for (String arg : args) {
|
for (Player p : (List<Player>)args.get("players")) {
|
||||||
OfflinePlayer p = Bukkit.getOfflinePlayer(arg);
|
|
||||||
|
|
||||||
if (p != null) {
|
|
||||||
BedwarsPlayer bwp = Game.instance.getPlayer(p);
|
BedwarsPlayer bwp = Game.instance.getPlayer(p);
|
||||||
|
|
||||||
if (bwp != null) {
|
if (bwp != null) {
|
||||||
bwp.kill(bwp.getPlayer().getName() + " definitely died with no admin intervention.");
|
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("unchecked")
|
||||||
};
|
public static Command revive(Command cmd) {
|
||||||
@SuppressWarnings("deprecation")
|
return cmd.player("players", false).setRecursive(true).setExecutor((sender, _cmd, args) -> {
|
||||||
public static CommandExecutor revive = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
|
||||||
if (Game.isStarted()) {
|
if (Game.isStarted()) {
|
||||||
for (String arg : args) {
|
for (Player p : (List<Player>)args.get("players")) {
|
||||||
OfflinePlayer p = Bukkit.getOfflinePlayer(arg);
|
|
||||||
|
|
||||||
if (p != null) {
|
|
||||||
BedwarsPlayer bwp = Game.instance.getPlayer(p);
|
BedwarsPlayer bwp = Game.instance.getPlayer(p);
|
||||||
|
|
||||||
if (bwp != null) {
|
if (bwp != null) {
|
||||||
bwp.revive();
|
bwp.revive();
|
||||||
Bukkit.broadcastMessage("Player " + p.getName() + " revived!");
|
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) -> {
|
public static Command start(Command cmd) {
|
||||||
if (args.length == 0) {
|
return cmd.setExecutor((sender, _cmd, args) -> {
|
||||||
if (!Game.isStarted()) {
|
if (!Game.isStarted()) {
|
||||||
Game.start();
|
Game.start();
|
||||||
sender.sendMessage("Started the game!");
|
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 Command stop(Command cmd) {
|
||||||
};
|
return cmd.setExecutor((sender, _cmd, args) -> {
|
||||||
public static CommandExecutor stop = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
|
||||||
if (args.length == 0) {
|
|
||||||
if (Game.isStarted()) {
|
if (Game.isStarted()) {
|
||||||
Game.stop();
|
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) -> {
|
private static Command basesArg() {
|
||||||
if (args.length == 6 && args[5].length() == 1) {
|
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 (!Game.isStarted()) {
|
||||||
if (Utility.isParsable(args[2])) {
|
String name = args.get("name").toString().toLowerCase();
|
||||||
if (Utility.isParsable(args[3])) {
|
Material wool = (Material)args.get("wool");
|
||||||
if (Utility.isParsable(args[4])) {
|
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) {
|
if (Config.instance.getColor(name.toLowerCase()) == null) {
|
||||||
Config.instance.getColors().add(new TeamColor(name.toLowerCase(), wool,
|
Config.instance.getColors().add(new TeamColor(name, wool, Color.fromRGB(r, g, b), chatColor));
|
||||||
Color.fromRGB(
|
|
||||||
Integer.parseInt(args[2]),
|
|
||||||
Integer.parseInt(args[3]),
|
|
||||||
Integer.parseInt(args[4])
|
|
||||||
),
|
|
||||||
chatId
|
|
||||||
));
|
|
||||||
Config.instance.save(confFile);
|
Config.instance.save(confFile);
|
||||||
sender.sendMessage("New base was created!");
|
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 return "Can't make modifications to the map while a game is ongoing!";
|
||||||
} 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 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) -> {
|
public static Command baseRemove(Command cmd) {
|
||||||
if (args.length == 1) {
|
return cmd
|
||||||
TeamColor color = Config.instance.getColor(args[0]);
|
.addChild(basesArg())
|
||||||
if (color != null) {
|
.setExecutor((sender, _cmd, args) -> {
|
||||||
|
TeamColor color = (TeamColor)args.get("team");
|
||||||
Config.instance.getColors().remove(color);
|
Config.instance.getColors().remove(color);
|
||||||
Config.instance.save(confFile);
|
Config.instance.save(confFile);
|
||||||
sender.sendMessage("Base removed!");
|
sender.sendMessage("Base removed!");
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else sender.sendMessage("Base doesn't exist!");
|
public static Command baseSetSpawn(Command cmd) {
|
||||||
}
|
return cmd
|
||||||
else sender.sendMessage("Invalid syntax! Syntax: /bw conf base del <name>");
|
.addChild(basesArg())
|
||||||
};
|
.location("location")
|
||||||
public static CommandExecutor baseSetSpawn = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
.setExecutor((sender, _cmd, args) -> {
|
||||||
boolean aligned = args.length == 2 && args[1].equals("aligned");
|
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);
|
color.setSpawnLocation(loc);
|
||||||
Config.instance.save(confFile);
|
Config.instance.save(confFile);
|
||||||
sender.sendMessage("Base spawn set to your current location");
|
sender.sendMessage("Base spawn set");
|
||||||
}
|
|
||||||
else sender.sendMessage("Base doesn't exist!");
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else sender.sendMessage("This commands is for players only!");
|
public static Command baseSetGenerator(Command cmd) {
|
||||||
}
|
return cmd
|
||||||
else sender.sendMessage("Invalid syntax! Syntax: /bw conf base spawn [aligned]");
|
.addChild(basesArg())
|
||||||
};
|
.location("location")
|
||||||
public static CommandExecutor baseSetGenerator = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
.setExecutor((sender, _cmd, args) -> {
|
||||||
boolean aligned = args.length == 2 && args[1].equals("aligned");
|
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);
|
color.setGeneratorLocation(loc);
|
||||||
Config.instance.save(confFile);
|
Config.instance.save(confFile);
|
||||||
sender.sendMessage("Base generator set to your current location");
|
sender.sendMessage("Base generator set");
|
||||||
}
|
|
||||||
else sender.sendMessage("Base doesn't exist!");
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else sender.sendMessage("This commands is for players only!");
|
public static Command baseSetBed(Command cmd) {
|
||||||
}
|
return cmd
|
||||||
else sender.sendMessage("Invalid syntax! Syntax: /bw conf base gen [aligned]");
|
.addChild(basesArg())
|
||||||
};
|
.location("location")
|
||||||
public static CommandExecutor baseSetBed = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
.setExecutor((sender, _cmd, args) -> {
|
||||||
boolean aligned = args.length == 2 && args[1].equals("aligned");
|
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);
|
color.setBedLocation(loc);
|
||||||
Config.instance.save(confFile);
|
Config.instance.save(confFile);
|
||||||
sender.sendMessage("Base bed set to your current location");
|
sender.sendMessage("Base bed set");
|
||||||
}
|
|
||||||
else sender.sendMessage("Base doesn't exist!");
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
else sender.sendMessage("This commands is for players only!");
|
public static Command baseList(Command cmd) {
|
||||||
}
|
return cmd
|
||||||
else sender.sendMessage("Invalid syntax! Syntax: /bw conf base bed [aligned]");
|
.setExecutor((sender, _cmd, args) -> {
|
||||||
};
|
List<TeamColor> colors = Config.instance.getColors();
|
||||||
public static CommandExecutor baseList = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
|
||||||
if (args.length == 0) {
|
|
||||||
ArrayList<TeamColor> colors = Config.instance.getColors();
|
|
||||||
|
|
||||||
if (colors.size() != 0) {
|
if (colors.size() != 0) {
|
||||||
sender.sendMessage("Bases:");
|
sender.sendMessage("Bases:");
|
||||||
for (TeamColor color : colors) {
|
for (TeamColor color : colors) {
|
||||||
sender.sendMessage("§" + color.getChatColor() + color.getName() + "§r" + (
|
ComponentBuilder cb = new ComponentBuilder().append(color.getName()).color(color.getChatColor());
|
||||||
color.isFullySpecified() ? "" : " (not fully specified)"
|
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("No bases found.");
|
||||||
}
|
|
||||||
else sender.sendMessage("Invalid syntax! No parameters required");
|
|
||||||
};
|
|
||||||
|
|
||||||
public static CommandExecutor breakBed = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
return null;
|
||||||
if (!Game.isStarted()) {
|
});
|
||||||
sender.sendMessage("§4A game hasn't been started yet.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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<>();
|
ArrayList<Team> teams = new ArrayList<>();
|
||||||
|
for (TeamColor color : colors) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Team team = Game.instance.getTeam(color);
|
Team team = Game.instance.getTeam(color);
|
||||||
|
|
||||||
if (team == null) {
|
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);
|
teams.add(team);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Team team : teams) {
|
for (Team team : teams) {
|
||||||
if (!team.destroyBed(null))
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean aligned = args.length == 1 && args[0] == "aligned";
|
return null;
|
||||||
|
});
|
||||||
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 createDiamondGen(Command cmd) {
|
||||||
|
return cmd.location("location").setExecutor((sender, _cmd, args) -> {
|
||||||
|
Location loc = (Location)args.get("location");
|
||||||
Config.instance.getDiamondGenerators().add(loc);
|
Config.instance.getDiamondGenerators().add(loc);
|
||||||
Config.instance.save(confFile);
|
Config.instance.save(confFile);
|
||||||
|
sender.sendMessage("§aGenerator added!");
|
||||||
p.sendMessage("§aGenerator added!");
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else sender.sendMessage("§4Only a player may execute this command.");
|
public static Command createEmeraldGen(Command cmd) {
|
||||||
};
|
return cmd.location("location").setExecutor((sender, _cmd, args) -> {
|
||||||
public static CommandExecutor createEmeraldGen = (CommandSender sender, Command cmd, String alias, String[] args) -> {
|
Location loc = (Location)args.get("location");
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
Config.instance.getEmeraldGenerators().add(loc);
|
Config.instance.getEmeraldGenerators().add(loc);
|
||||||
Config.instance.save(confFile);
|
Config.instance.save(confFile);
|
||||||
|
sender.sendMessage("§aGenerator added!");
|
||||||
p.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;
|
package me.topchetoeu.bedwars;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.ArmorStand;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.entity.Villager;
|
import org.bukkit.entity.Villager;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
@ -54,7 +46,7 @@ public class Main extends JavaPlugin implements Listener {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File confFile = new File(getDataFolder(), "config.yml");
|
// private File confFile = new File(getDataFolder(), "config.yml");
|
||||||
private int getGameSize() {
|
private int getGameSize() {
|
||||||
return Config.instance.getTeamSize() * Config.instance.getColors().size();
|
return Config.instance.getTeamSize() * Config.instance.getColors().size();
|
||||||
}
|
}
|
||||||
@ -135,36 +127,12 @@ public class Main extends JavaPlugin implements Listener {
|
|||||||
getDataFolder().mkdir();
|
getDataFolder().mkdir();
|
||||||
File conf = new File(getDataFolder(), "config.yml");
|
File conf = new File(getDataFolder(), "config.yml");
|
||||||
if (!conf.exists())
|
if (!conf.exists())
|
||||||
try {
|
conf.createNewFile();
|
||||||
YamlConfiguration.loadConfiguration(
|
|
||||||
new InputStreamReader(
|
|
||||||
getClass()
|
|
||||||
.getClassLoader()
|
|
||||||
.getResourceAsStream("config.yml")
|
|
||||||
)
|
|
||||||
).save(confFile);
|
|
||||||
}
|
|
||||||
catch (IOException e) { /* Everything is fine */ }
|
|
||||||
|
|
||||||
// Deprecation warnings are for beginners
|
|
||||||
Config.load(conf);
|
Config.load(conf);
|
||||||
File defaultFavs = new File(getDataFolder(), "default-favourites.yml");
|
File defaultFavs = new File(getDataFolder(), "default-favourites.yml");
|
||||||
|
|
||||||
if (!defaultFavs.exists()) {
|
if (!defaultFavs.exists())
|
||||||
try {
|
defaultFavs.createNewFile();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File favsDir = new File(getDataFolder(), "favourites");
|
File favsDir = new File(getDataFolder(), "favourites");
|
||||||
|
|
||||||
@ -197,110 +165,58 @@ public class Main extends JavaPlugin implements Listener {
|
|||||||
v.setAI(false);
|
v.setAI(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
Command cmd = new Command("bedwars", "bw").setExecutor(Commands._default);
|
Command cmd = Command.createLiteral("bedwars", "bw");
|
||||||
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;
|
|
||||||
|
|
||||||
p.getInventory().addItem(Utility.namedItem(new ItemStack(Material.VILLAGER_SPAWN_EGG), "§rTrader spawner"));
|
cmd.literal("help").setExecutor(CommandExecutors.help()).string("args", false).setRecursive(true).setExecutor(CommandExecutors.help());
|
||||||
p.getInventory().addItem(Utility.namedItem(new ItemStack(Material.STICK), "§rTrader eradicator"));
|
Commands.start(cmd.literal("start"));
|
||||||
}
|
Commands.stop(cmd.literal("stop"));
|
||||||
}
|
|
||||||
})
|
Commands.kill(cmd.literal("kill"));
|
||||||
.setHelpMessage("Gives you tools to manage traders")
|
Commands.revive(cmd.literal("revive"));
|
||||||
)
|
|
||||||
.attachCommand(new Command("config", "conf", "settings")
|
Command config = cmd.literal("configuration", "config", "conf");
|
||||||
.setExecutor(Commands._default)
|
Command base = config.literal("base");
|
||||||
.setHelpMessage("Command for configuring the map")
|
Command generator = config.literal("generator", "gen");
|
||||||
.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")
|
Commands.baseAdd(base.literal("add"));
|
||||||
)
|
Commands.baseRemove(base.literal("remove"));
|
||||||
.attachCommand(new Command("base", "b")
|
Commands.baseSetSpawn(base.literal("setspawn", "spawn"));
|
||||||
.setExecutor(Commands._default)
|
Commands.baseSetGenerator(base.literal("setgenerator", "generator", "gen"));
|
||||||
.setHelpMessage("Command for configuring separate bases")
|
Commands.baseSetBed(base.literal("setbed", "bed"));
|
||||||
.attachCommand(new Command("new", "add", "create", "c")
|
Commands.baseList(base.literal("list", "l"));
|
||||||
.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'")
|
Commands.createDiamondGen(generator.literal("diamond"));
|
||||||
)
|
Commands.createEmeraldGen(generator.literal("emerald", "em"));
|
||||||
.attachCommand(new Command("remove", "delete", "del", "d")
|
Commands.clearGens(generator.literal("emerald", "em"));
|
||||||
.setExecutor(Commands.baseRemove)
|
|
||||||
.setHelpMessage("Removes a base with the selected name")
|
Commands.breakBed(cmd.literal("breakbed", "cheat", "bedishonest", "abusepowers"));
|
||||||
)
|
|
||||||
.attachCommand(new Command("setbed", "bed", "b")
|
cmd.register(this);
|
||||||
.setExecutor(Commands.baseSetBed)
|
// .attachCommand(new Command("respawn", "revive")
|
||||||
.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")
|
// .setExecutor(Commands.revive)
|
||||||
)
|
// .setHelpMessage("Respawns a spectator, if he has a bed, he is immediatly respawned"))
|
||||||
.attachCommand(new Command("setgenerator", "generator", "setgen", "gen", "g")
|
// .attachCommand(new Command("breakbed", "eliminateteam")
|
||||||
.setExecutor(Commands.baseSetGenerator)
|
// .setExecutor(Commands.breakBed)
|
||||||
.setHelpMessage("Sets the location of the generator. Anyone within 2 blocks of it will pick up the produced items")
|
// .setHelpMessage("Destoys the bed of a team")
|
||||||
)
|
// )
|
||||||
.attachCommand(new Command("setspawn", "spawn", "s")
|
// .attachCommand(new Command("eliminate")
|
||||||
.setExecutor(Commands.baseSetSpawn)
|
// .setHelpMessage("Eliminates a player")
|
||||||
.setHelpMessage("Sets the location where players of the team will respawn")
|
// )
|
||||||
)
|
// .attachCommand(new Command("killteam")
|
||||||
.attachCommand(new Command("list", "l")
|
// .setHelpMessage("Kills all players of a team")
|
||||||
.setExecutor(Commands.baseList)
|
// )
|
||||||
.setHelpMessage("Lists all bases")
|
// .attachCommand(new Command("villagertools", "villager", "trader")
|
||||||
)
|
// .setExecutor((sender, _cmd, alias, args) -> {
|
||||||
)
|
// if (args.length == 0) {
|
||||||
.attachCommand(new Command("generator", "gen", "g")
|
// if (sender instanceof Player) {
|
||||||
.setExecutor(Commands._default)
|
// Player p = (Player)sender;
|
||||||
.setHelpMessage("Command for configuring the global generators")
|
// Traders.instance.give(p);
|
||||||
.attachCommand(new Command("diamond", "d")
|
// }
|
||||||
.setExecutor(Commands.createDiamondGen)
|
// }
|
||||||
.setHelpMessage("Creates a diamond generator in (approximately) your position")
|
// })
|
||||||
)
|
// .setHelpMessage("Gives you tools to manage traders")
|
||||||
.attachCommand(new Command("emerald", "e")
|
// )
|
||||||
.setExecutor(Commands.createEmeraldGen)
|
// .register(this);
|
||||||
.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);
|
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(this, 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.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||||
|
|
||||||
public class Utility {
|
public class Utility {
|
||||||
public static void sendTitle(Player p, String title, String subtitle, int fadeIn, int duration, int fadeout) {
|
public static void sendTitle(Player p, String title, String subtitle, int fadeIn, int duration, int fadeout) {
|
||||||
p.sendTitle(title, subtitle, fadeIn, duration, fadeout);
|
p.sendTitle(title, subtitle, fadeIn, duration, fadeout);
|
||||||
@ -54,12 +57,11 @@ public class Utility {
|
|||||||
i.setItemMeta(meta);
|
i.setItemMeta(meta);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
public static String getItemName(Material item) {
|
public static TranslatableComponent getItemName(Material item) {
|
||||||
return CraftItemStack.asNMSCopy(new ItemStack(item)).n();
|
return new TranslatableComponent(CraftItemStack.asNMSCopy(new ItemStack(item)).n());
|
||||||
}
|
}
|
||||||
public static String getItemName(ItemStack item) {
|
public static TranslatableComponent getItemName(ItemStack item) {
|
||||||
if (item.getItemMeta().hasDisplayName()) return item.getItemMeta().getDisplayName();
|
return new TranslatableComponent(CraftItemStack.asNMSCopy(new ItemStack(item)).n());
|
||||||
return CraftItemStack.asNMSCopy(item).n();
|
|
||||||
}
|
}
|
||||||
public static void takeOne(Player p, EquipmentSlot e) {
|
public static void takeOne(Player p, EquipmentSlot e) {
|
||||||
ItemStack i = p.getInventory().getItem(e);
|
ItemStack i = p.getInventory().getItem(e);
|
||||||
@ -179,4 +181,54 @@ public class Utility {
|
|||||||
if (obj == null) obj = "null";
|
if (obj == null) obj = "null";
|
||||||
p.sendMessage(obj.toString());
|
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;
|
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.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.command.CommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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 {
|
public class Command {
|
||||||
private String[] aliases;
|
|
||||||
private String name;
|
private String name;
|
||||||
private String helpMessage;
|
private String helpMessage;
|
||||||
private CommandExecutor fallbackExecutor;
|
private CommandExecutor executor;
|
||||||
private HashSet<Command> attachedCommands = new HashSet<>();
|
private HashSet<Command> children = new HashSet<>();
|
||||||
|
private ArgParser parser;
|
||||||
|
private boolean recursive = false;
|
||||||
|
|
||||||
private JavaPlugin parent = null;
|
private Set<JavaPlugin> parents = new HashSet<>();
|
||||||
|
|
||||||
public String[] getAliases() {
|
|
||||||
return aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
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() {
|
public String getHelpMessage() {
|
||||||
return helpMessage;
|
return helpMessage;
|
||||||
}
|
}
|
||||||
@ -31,116 +59,264 @@ public class Command {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandExecutor getFallbackExecutor() {
|
public CommandExecutor getExecutor() {
|
||||||
return fallbackExecutor;
|
return executor;
|
||||||
}
|
}
|
||||||
public Command setExecutor(CommandExecutor val) {
|
public Command setExecutor(CommandExecutor val) {
|
||||||
fallbackExecutor = val;
|
executor = val;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command attachCommand(Command cmd) {
|
public Command addChild(Command cmd) {
|
||||||
if (cmd == null) throw new RuntimeException("cmd is null");
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
public Command detachCommand(Command cmd) {
|
public boolean hasChild(Command cmd) {
|
||||||
if (cmd == null) throw new RuntimeException("cmd is null");
|
|
||||||
attachedCommands.remove(cmd);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public boolean commandAttached(Command cmd) {
|
|
||||||
if (cmd == null) return false;
|
if (cmd == null) return false;
|
||||||
return attachedCommands.contains(cmd);
|
return children.contains(cmd);
|
||||||
}
|
}
|
||||||
public Command[] getAttachedCommands() {
|
public Set<Command> getChildren() {
|
||||||
return attachedCommands.toArray(Command[]::new);
|
return Collections.unmodifiableSet(children);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(CommandSender sender, String alias, String[] args) {
|
public Command setRecursive(boolean val) {
|
||||||
Command cmd;
|
recursive = val;
|
||||||
if (args.length == 0) cmd = null;
|
return this;
|
||||||
else cmd = getAttachedCommand(args[0]);
|
}
|
||||||
|
public boolean isRecursive() {
|
||||||
String[] newArgs;
|
return recursive;
|
||||||
if (args.length <= 1) newArgs = new String[0];
|
|
||||||
else {
|
|
||||||
newArgs = new String[args.length - 1];
|
|
||||||
System.arraycopy(args, 1, newArgs, 0, args.length - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd != null)
|
@SuppressWarnings("unchecked")
|
||||||
cmd.execute(sender, args[0], newArgs);
|
public void execute(CommandSender sender, String[] _args) {
|
||||||
else if (fallbackExecutor != null) fallbackExecutor.execute(
|
Command toExecute = this;
|
||||||
sender, this,
|
|
||||||
alias, args
|
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) {
|
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");
|
if (pl == null) throw new RuntimeException("pl is null");
|
||||||
parent = pl;
|
parents.add(pl);
|
||||||
pl.getCommand(name).setAliases(Arrays.asList(aliases));
|
|
||||||
pl.getCommand(name).setExecutor(new org.bukkit.command.CommandExecutor() {
|
|
||||||
|
|
||||||
@Override
|
LiteralArgParser parser = (LiteralArgParser)this.parser;
|
||||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String alias, String[] args) {
|
String name = parser.getLiteral();
|
||||||
execute(sender, alias, args);
|
|
||||||
|
pl.getCommand(name).setAliases(parser.getAliases());
|
||||||
|
pl.getCommand(name).setExecutor((sender, cmd, alias, args) -> {
|
||||||
|
execute(sender, args);
|
||||||
return true;
|
return true;
|
||||||
}
|
});
|
||||||
|
pl.getCommand(name).setTabCompleter((sender, cmd, alias, args) -> {
|
||||||
|
return tabComplete(sender, args);
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command getAttachedCommand(String alias) {
|
public Command(String name, ArgParser parser) {
|
||||||
String newAlias = alias.toLowerCase();
|
this.name = name;
|
||||||
for (Command command : attachedCommands) {
|
this.parser = parser;
|
||||||
if (command.name.equals(newAlias) || Arrays.stream(command.aliases).anyMatch(v -> v.equals(newAlias)))
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command(String name, String alias) {
|
public Command literal(String name) {
|
||||||
this.name = name;
|
Command cmd = createLiteral(name);
|
||||||
this.aliases = new String[] { alias };
|
addChild(cmd);
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
public Command(String name, String... aliases) {
|
public Command literal(String name, String ...aliases) {
|
||||||
this.name = name;
|
Command cmd = createLiteral(name, aliases);
|
||||||
this.aliases = aliases;
|
addChild(cmd);
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
public Command(String name, CommandExecutor executor, String... aliases) {
|
public Command location(String name) {
|
||||||
this.name = name;
|
Command cmd = createLocation(name);
|
||||||
this.aliases = aliases;
|
addChild(cmd);
|
||||||
this.fallbackExecutor = executor;
|
return cmd;
|
||||||
}
|
}
|
||||||
public Command(String name, String alias, Command... commands) {
|
public Command _enum(String name, Class<? extends Enum<?>> enumType, boolean caseInsensitive) {
|
||||||
this.name = name;
|
Command cmd = createEnum(name, enumType, caseInsensitive);
|
||||||
this.aliases = new String[] { alias };
|
addChild(cmd);
|
||||||
|
return cmd;
|
||||||
for (Command cmd : commands) {
|
|
||||||
attachCommand(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) {
|
public Command string(String name, boolean greedy) {
|
||||||
this.name = name;
|
Command cmd = createString(name, greedy);
|
||||||
this.aliases = aliases;
|
addChild(cmd);
|
||||||
|
return cmd;
|
||||||
for (Command cmd : commands) {
|
|
||||||
attachCommand(cmd);
|
|
||||||
}
|
}
|
||||||
|
public Command _int(String name) {
|
||||||
|
Command cmd = createInt(name);
|
||||||
|
addChild(cmd);
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
public Command(String name, String[] aliases, CommandExecutor executor, Command... commands) {
|
public Command collection(String name, SimpleCollectionQuery query, boolean caseInsensitive) {
|
||||||
this.name = name;
|
Command cmd = createCollection(name, query, caseInsensitive);
|
||||||
this.aliases = aliases;
|
addChild(cmd);
|
||||||
fallbackExecutor = executor;
|
return cmd;
|
||||||
|
|
||||||
for (Command cmd : commands) {
|
|
||||||
attachCommand(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;
|
package me.topchetoeu.bedwars.commandUtility;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public interface CommandExecutor {
|
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;
|
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 {
|
public class CommandExecutors {
|
||||||
private static String join(String[] arr, String separator) {
|
// private static List<String> getSyntaxes(Command cmd) {
|
||||||
if (arr.length == 0) return "";
|
// ArrayList<String> syntaxes = new ArrayList<>();
|
||||||
if (arr.length == 1) return arr[0];
|
|
||||||
|
|
||||||
String res = arr[0];
|
// for (Command child : cmd.getChildren()) {
|
||||||
|
// ArgParser parser = child.getParser();
|
||||||
|
|
||||||
for (int i = 1; i < arr.length; i++) {
|
// if (parser instanceof LiteralArgParser) {
|
||||||
res += separator + arr[i];
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 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) {
|
cmd = currCmd;
|
||||||
return new CommandExecutor() {
|
LiteralArgParser cmdParser = (LiteralArgParser)cmd.getParser();
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, Command cmd, String alias, String[] args) {
|
|
||||||
Command currCmd = mainCmd;
|
|
||||||
String path = "/" + mainCmd.getName();
|
|
||||||
|
|
||||||
for (String arg : args) {
|
sender.spigot().sendMessage(new ComponentBuilder()
|
||||||
currCmd = currCmd.getAttachedCommand(arg);
|
.append("Help for %s: ".formatted(path))
|
||||||
if (currCmd == null) {
|
.bold(true)
|
||||||
String msg = "Help can't be provided for the command.";
|
.create()
|
||||||
sender.sendMessage(msg);
|
);
|
||||||
return;
|
if (cmd.getHelpMessage() != null) sender.spigot().sendMessage(new ComponentBuilder()
|
||||||
}
|
.append(" " + cmd.getHelpMessage())
|
||||||
|
.create()
|
||||||
path += " " + currCmd.getName();
|
);
|
||||||
}
|
sender.spigot().sendMessage(new ComponentBuilder()
|
||||||
|
.append(" Aliases: ")
|
||||||
sender.sendMessage(path + ": " + (currCmd.getHelpMessage() == null ?
|
.bold(true)
|
||||||
"no help provided" :
|
.append(String.join(", ", cmdParser.getAliases()))
|
||||||
currCmd.getHelpMessage())
|
.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) {
|
for (Command child : currCmd.getChildren()) {
|
||||||
sender.sendMessage("Commands: ");
|
if (child.getParser() instanceof LiteralArgParser) {
|
||||||
for (Command subCmd : currCmd.getAttachedCommands()) {
|
sender.spigot().sendMessage(new ComponentBuilder()
|
||||||
sender.sendMessage(path + " " + subCmd.getName() + ": " + subCmd.getHelpMessage());
|
.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) {
|
public static CommandExecutor message(String msg) {
|
||||||
return new CommandExecutor() {
|
return (sender, cmd, args) -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, Command cmd, String alias, String[] args) {
|
|
||||||
sender.sendMessage(msg);
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
@ -18,9 +17,9 @@ public class Config {
|
|||||||
|
|
||||||
private int perTeam = 0;
|
private int perTeam = 0;
|
||||||
private Location respawnLocation;
|
private Location respawnLocation;
|
||||||
private ArrayList<TeamColor> colors;
|
private List<TeamColor> colors;
|
||||||
private ArrayList<Location> diamondGenerators;
|
private List<Location> diamondGenerators;
|
||||||
private ArrayList<Location> emeraldGenerators;
|
private List<Location> emeraldGenerators;
|
||||||
|
|
||||||
public Location getRespawnLocation() {
|
public Location getRespawnLocation() {
|
||||||
return respawnLocation;
|
return respawnLocation;
|
||||||
@ -36,18 +35,18 @@ public class Config {
|
|||||||
perTeam = size;
|
perTeam = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<TeamColor> getColors() {
|
public List<TeamColor> getColors() {
|
||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
public TeamColor getColor(String name) {
|
public TeamColor getColor(String name) {
|
||||||
return Config.instance.getColors()
|
return getColors()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(v -> v.getName().equals(name.toLowerCase()))
|
.filter(v -> v.getName().equals(name.toLowerCase()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Location> getDiamondGenerators() {
|
public List<Location> getDiamondGenerators() {
|
||||||
return diamondGenerators;
|
return diamondGenerators;
|
||||||
}
|
}
|
||||||
public Location getClosestDiamondGenerator(Location loc) {
|
public Location getClosestDiamondGenerator(Location loc) {
|
||||||
@ -72,7 +71,7 @@ public class Config {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Location> getEmeraldGenerators() {
|
public List<Location> getEmeraldGenerators() {
|
||||||
return emeraldGenerators;
|
return emeraldGenerators;
|
||||||
}
|
}
|
||||||
public Location getClosestEmeraldGenerator(Location loc) {
|
public Location getClosestEmeraldGenerator(Location loc) {
|
||||||
@ -97,10 +96,6 @@ public class Config {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<?> toList(Stream<?> s) {
|
|
||||||
return new ArrayList<>(s.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void load(File confFile) {
|
public static void load(File confFile) {
|
||||||
Configuration conf = YamlConfiguration.loadConfiguration(confFile);
|
Configuration conf = YamlConfiguration.loadConfiguration(confFile);
|
||||||
@ -109,21 +104,22 @@ public class Config {
|
|||||||
|
|
||||||
c.perTeam = conf.getInt("perTeam");
|
c.perTeam = conf.getInt("perTeam");
|
||||||
if (conf.get("respawnLocation") != null) c.respawnLocation = Location.deserialize(conf.getConfigurationSection("respawnLocation").getValues(false));
|
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")
|
.getMapList("colors")
|
||||||
.stream()
|
.stream()
|
||||||
.map(v -> TeamColor.deserialize((Map<String, Object>)v))
|
.map(v -> TeamColor.deserialize((Map<String, Object>)v))
|
||||||
);
|
.toList());
|
||||||
c.diamondGenerators = (ArrayList<Location>)toList(conf
|
c.diamondGenerators = new ArrayList<>(conf
|
||||||
.getMapList("diamondGenerators")
|
.getMapList("diamondGenerators")
|
||||||
.stream()
|
.stream()
|
||||||
.map(v -> Location.deserialize((Map<String, Object>)v))
|
.map(v -> Location.deserialize((Map<String, Object>)v))
|
||||||
);
|
.toList())
|
||||||
c.emeraldGenerators = (ArrayList<Location>)toList(conf
|
;
|
||||||
|
c.emeraldGenerators = new ArrayList<>(conf
|
||||||
.getMapList("emeraldGenerators")
|
.getMapList("emeraldGenerators")
|
||||||
.stream()
|
.stream()
|
||||||
.map(v -> Location.deserialize((Map<String, Object>)v))
|
.map(v -> Location.deserialize((Map<String, Object>)v))
|
||||||
);
|
.toList());
|
||||||
|
|
||||||
instance = c;
|
instance = c;
|
||||||
}
|
}
|
||||||
@ -132,9 +128,9 @@ public class Config {
|
|||||||
FileConfiguration conf = YamlConfiguration.loadConfiguration(confFile);
|
FileConfiguration conf = YamlConfiguration.loadConfiguration(confFile);
|
||||||
|
|
||||||
conf.set("perTeam", perTeam);
|
conf.set("perTeam", perTeam);
|
||||||
conf.set("colors", toList(colors.stream().map(v -> v.serialize())));
|
conf.set("colors", colors.stream().map(v -> v.serialize()).toList());
|
||||||
conf.set("diamondGenerators", toList(diamondGenerators.stream().map(v -> v.serialize())));
|
conf.set("diamondGenerators", diamondGenerators.stream().map(v -> v.serialize()).toList());
|
||||||
conf.set("emeraldGenerators", toList(emeraldGenerators.stream().map(v -> v.serialize())));
|
conf.set("emeraldGenerators", emeraldGenerators.stream().map(v -> v.serialize()).toList());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conf.save(confFile);
|
conf.save(confFile);
|
||||||
|
@ -76,8 +76,8 @@ public class Game implements Listener, AutoCloseable {
|
|||||||
ScoreboardManager.updateAll();
|
ScoreboardManager.updateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stop(boolean immediatly) {
|
public static void stop(boolean immediately) {
|
||||||
if (immediatly) stop();
|
if (immediately) stop();
|
||||||
else Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> stop(), 20 * 5);
|
else Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> stop(), 20 * 5);
|
||||||
}
|
}
|
||||||
public static boolean isStarted() {
|
public static boolean isStarted() {
|
||||||
@ -102,7 +102,7 @@ public class Game implements Listener, AutoCloseable {
|
|||||||
|
|
||||||
public void win(TeamColor color) {
|
public void win(TeamColor color) {
|
||||||
getTeam(color).sendTitle("You won!", "", 0, 20 * 5, 0);
|
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);
|
stop(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ public class Game implements Listener, AutoCloseable {
|
|||||||
spectators.add(removed);
|
spectators.add(removed);
|
||||||
if (removed.isOnline()) {
|
if (removed.isOnline()) {
|
||||||
removed.getPlayer().setGameMode(GameMode.SPECTATOR);
|
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");
|
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.Objective;
|
||||||
import org.bukkit.scoreboard.Scoreboard;
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
|
||||||
public class ScoreboardManager {
|
public class ScoreboardManager {
|
||||||
private static Hashtable<UUID, Scoreboard> scoreboards = new Hashtable<>();
|
private static Hashtable<UUID, Scoreboard> scoreboards = new Hashtable<>();
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ public class ScoreboardManager {
|
|||||||
if (v.getRemainingPlayers() == 0) teamCounter = "§4✖";
|
if (v.getRemainingPlayers() == 0) teamCounter = "§4✖";
|
||||||
else if (!v.hasBed()) teamCounter = Integer.toString(v.getRemainingPlayers());
|
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)) {
|
if (v.hasPlayer(p)) {
|
||||||
newStr = (newStr + "§r (you)").replaceAll("§([0-9a-z])", "§$1§l");
|
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.Main;
|
||||||
import me.topchetoeu.bedwars.Utility;
|
import me.topchetoeu.bedwars.Utility;
|
||||||
import me.topchetoeu.bedwars.engine.trader.upgrades.TeamUpgrade;
|
import me.topchetoeu.bedwars.engine.trader.upgrades.TeamUpgrade;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
|
||||||
public class Team implements Listener, AutoCloseable {
|
public class Team implements Listener, AutoCloseable {
|
||||||
private TeamColor color;
|
private TeamColor color;
|
||||||
@ -66,10 +67,10 @@ public class Team implements Listener, AutoCloseable {
|
|||||||
if (bwp.isOnline()) {
|
if (bwp.isOnline()) {
|
||||||
Player p = bwp.getOnlinePlayer();
|
Player p = bwp.getOnlinePlayer();
|
||||||
|
|
||||||
String msg = color.getColorName() + "§r's bed was destroyed";
|
ComponentBuilder cb = new ComponentBuilder().append(color.getColorName()).append("'s bed was destroyed").reset();
|
||||||
if (player != null) msg += " by " + player.getName();
|
if (player != null) cb.append(" by " + player.getName());
|
||||||
msg += ".";
|
cb.append(".");
|
||||||
Bukkit.broadcastMessage(msg);
|
Bukkit.spigot().broadcast(cb.create());
|
||||||
|
|
||||||
Utility.sendTitle(p, "Bed destroyed!", "You will no longer respawn!", 5, 35, 10);
|
Utility.sendTitle(p, "Bed destroyed!", "You will no longer respawn!", 5, 35, 10);
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1, 1);
|
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);
|
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()) {
|
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
if (players.stream().noneMatch(v -> v.getPlayer().getUniqueId().equals(p.getUniqueId())))
|
if (players.stream().noneMatch(v -> v.getPlayer().getUniqueId().equals(p.getUniqueId())))
|
||||||
Utility.sendTitle(p, title, subtitle, fadein, duration, fadeout);
|
Utility.sendTitle(p, title, subtitle, fadein, duration, fadeout);
|
||||||
|
@ -8,10 +8,15 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
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 {
|
public class TeamColor implements ConfigurationSerializable {
|
||||||
private String name;
|
private String name;
|
||||||
private Material wool;
|
private Material wool;
|
||||||
private char chatColor;
|
private ChatColor chatColor;
|
||||||
private Color color;
|
private Color color;
|
||||||
private Location bed = null;
|
private Location bed = null;
|
||||||
private Location spawnLocation = null;
|
private Location spawnLocation = null;
|
||||||
@ -20,8 +25,8 @@ public class TeamColor implements ConfigurationSerializable {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
public String getColorName() {
|
public BaseComponent[] getColorName() {
|
||||||
return String.format("§%c%s%s", chatColor, name.substring(0, 1).toUpperCase(), name.substring(1));
|
return new ComponentBuilder().append(name).color(chatColor).create();
|
||||||
}
|
}
|
||||||
public Material getWoolMaterial() {
|
public Material getWoolMaterial() {
|
||||||
return wool;
|
return wool;
|
||||||
@ -29,7 +34,7 @@ public class TeamColor implements ConfigurationSerializable {
|
|||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
public char getChatColor() {
|
public ChatColor getChatColor() {
|
||||||
return chatColor;
|
return chatColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +63,7 @@ public class TeamColor implements ConfigurationSerializable {
|
|||||||
return bed != null && spawnLocation != null && generatorLocation != null;
|
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.name = name;
|
||||||
this.wool = wool;
|
this.wool = wool;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
@ -69,9 +74,9 @@ public class TeamColor implements ConfigurationSerializable {
|
|||||||
Map<String, Object> map = new Hashtable<>();
|
Map<String, Object> map = new Hashtable<>();
|
||||||
|
|
||||||
map.put("name", name);
|
map.put("name", name);
|
||||||
map.put("wool", wool.getKey().toString());
|
map.put("wool", wool.getKey().getKey().toLowerCase());
|
||||||
map.put("color", color.serialize());
|
map.put("color", color.serialize());
|
||||||
map.put("chatColor", chatColor);
|
map.put("chatColor", chatColor.getName());
|
||||||
|
|
||||||
if (bed != null) map.put("bed", bed.serialize());
|
if (bed != null) map.put("bed", bed.serialize());
|
||||||
if (generatorLocation != null) map.put("generator", generatorLocation.serialize());
|
if (generatorLocation != null) map.put("generator", generatorLocation.serialize());
|
||||||
@ -79,13 +84,13 @@ public class TeamColor implements ConfigurationSerializable {
|
|||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked" })
|
||||||
public static TeamColor deserialize(Map<String, Object> map) {
|
public static TeamColor deserialize(Map<String, Object> map) {
|
||||||
TeamColor color = new TeamColor(
|
TeamColor color = new TeamColor(
|
||||||
(String)map.get("name"),
|
map.get("name").toString(),
|
||||||
Material.getMaterial(map.get("wool").toString().toUpperCase()),
|
Material.getMaterial(map.get("wool").toString().toUpperCase()),
|
||||||
Color.deserialize((Map<String, Object>)map.get("color")),
|
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")));
|
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.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
|
||||||
public interface Deal {
|
public interface Deal {
|
||||||
public ItemStack getDealItem(Player p);
|
public ItemStack getDealItem(Player p);
|
||||||
public String getDealName(Player p);
|
public BaseComponent[] getDealName(Player p);
|
||||||
public Material getPriceType(Player p);
|
public Material getPriceType(Player p);
|
||||||
public int getPrice(Player p);
|
public int getPrice(Player p);
|
||||||
public boolean alreadyBought(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.Main;
|
||||||
import me.topchetoeu.bedwars.Utility;
|
import me.topchetoeu.bedwars.Utility;
|
||||||
import me.topchetoeu.bedwars.engine.trader.dealTypes.ItemDeal;
|
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.
|
// Very bad code.
|
||||||
public class TraderGUI implements Listener {
|
public class TraderGUI implements Listener {
|
||||||
@ -43,11 +46,11 @@ public class TraderGUI implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack generateDealItem(Deal d, boolean addFavouriteLore) {
|
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)";
|
if (d.alreadyBought(player)) name += " §4(already unlocked)";
|
||||||
else name += String.format(" (%dx %s)",
|
else name += String.format(" (%dx %s)",
|
||||||
d.getPrice(player),
|
d.getPrice(player),
|
||||||
Utility.getItemName(d.getPriceType(player))
|
BaseComponent.toLegacyText(Utility.getItemName(d.getPriceType(player)))
|
||||||
);
|
);
|
||||||
|
|
||||||
ItemStack item = Utility.copyNamedItem(d.getDealItem(player), name);
|
ItemStack item = Utility.copyNamedItem(d.getDealItem(player), name);
|
||||||
@ -170,6 +173,7 @@ public class TraderGUI implements Listener {
|
|||||||
|
|
||||||
player.getInventory().setContents(inv);
|
player.getInventory().setContents(inv);
|
||||||
|
|
||||||
|
player.spigot().sendMessage(new ComponentBuilder().append("You just purchased ").append(deal.getDealName(player)).create());
|
||||||
deal.commence(player);
|
deal.commence(player);
|
||||||
updateSection();
|
updateSection();
|
||||||
if (player.getInventory().contains(Material.STONE_SWORD) ||
|
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);
|
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_YES, 1, 1);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
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.sections = Sections.getSections();
|
||||||
this.player = p;
|
this.player = p;
|
||||||
Bukkit.getPluginManager().registerEvents(this, Main.getInstance());
|
Bukkit.getPluginManager().registerEvents(this, Main.getInstance());
|
||||||
|
@ -29,6 +29,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import me.topchetoeu.bedwars.Main;
|
import me.topchetoeu.bedwars.Main;
|
||||||
|
import me.topchetoeu.bedwars.Utility;
|
||||||
|
|
||||||
public class Traders implements Listener {
|
public class Traders implements Listener {
|
||||||
public static Traders instance = null;
|
public static Traders instance = null;
|
||||||
@ -36,6 +37,8 @@ public class Traders implements Listener {
|
|||||||
private List<UUID> villagers = new ArrayList<>();
|
private List<UUID> villagers = new ArrayList<>();
|
||||||
private File file;
|
private File file;
|
||||||
|
|
||||||
|
private final ItemStack eradicator, spawner;
|
||||||
|
|
||||||
private void write() {
|
private void write() {
|
||||||
try {
|
try {
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file));
|
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) {
|
public Villager summonVillager(Location loc) {
|
||||||
Villager vil = (Villager)loc.getWorld().spawnEntity(loc, EntityType.VILLAGER);
|
Villager vil = (Villager)loc.getWorld().spawnEntity(loc, EntityType.VILLAGER);
|
||||||
|
|
||||||
@ -78,9 +85,7 @@ public class Traders implements Listener {
|
|||||||
private void onUse(PlayerInteractEvent e) {
|
private void onUse(PlayerInteractEvent e) {
|
||||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
if (e.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
||||||
e.hasItem() &&
|
e.hasItem() &&
|
||||||
e.getItem().hasItemMeta() &&
|
spawner.getItemMeta().equals(e.getItem().getItemMeta())) {
|
||||||
e.getItem().getItemMeta().hasDisplayName() &&
|
|
||||||
e.getItem().getItemMeta().getDisplayName() == "§rTrader spawner") {
|
|
||||||
if (e.getItem().getType() == Material.VILLAGER_SPAWN_EGG) {
|
if (e.getItem().getType() == Material.VILLAGER_SPAWN_EGG) {
|
||||||
int yaw = (int)e.getPlayer().getLocation().getYaw() - 45;
|
int yaw = (int)e.getPlayer().getLocation().getYaw() - 45;
|
||||||
if (yaw < 0) yaw += 360;
|
if (yaw < 0) yaw += 360;
|
||||||
@ -108,6 +113,8 @@ public class Traders implements Listener {
|
|||||||
|
|
||||||
e.getPlayer().sendMessage("Trader spawned!");
|
e.getPlayer().sendMessage("Trader spawned!");
|
||||||
e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_YES, 1, 1);
|
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 &&
|
if (hand != null &&
|
||||||
hand.hasItemMeta() &&
|
hand.hasItemMeta() &&
|
||||||
hand.getItemMeta().hasDisplayName() &&
|
eradicator.getItemMeta().equals(hand.getItemMeta())) {
|
||||||
hand.getItemMeta().getDisplayName().equals("§rTrader eradicator")) {
|
|
||||||
if (hand.getType() == Material.STICK) {
|
if (hand.getType() == Material.STICK) {
|
||||||
villagers.remove(v.getUniqueId());
|
villagers.remove(v.getUniqueId());
|
||||||
write();
|
write();
|
||||||
@ -162,6 +168,9 @@ public class Traders implements Listener {
|
|||||||
|
|
||||||
file = tradersFile;
|
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());
|
Bukkit.getPluginManager().registerEvents(this, Main.getInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package me.topchetoeu.bedwars.engine.trader.dealTypes;
|
package me.topchetoeu.bedwars.engine.trader.dealTypes;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import me.topchetoeu.bedwars.engine.Game;
|
import me.topchetoeu.bedwars.engine.Game;
|
||||||
import me.topchetoeu.bedwars.engine.trader.Deal;
|
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 {
|
public class EnforcedRankedDeal implements Deal {
|
||||||
private Rank soldRank;
|
private Rank soldRank;
|
||||||
@ -24,8 +25,8 @@ public class EnforcedRankedDeal implements Deal {
|
|||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getDealName(Player p) {
|
public BaseComponent[] getDealName(Player p) {
|
||||||
return soldRank.getNextTier(p).getDisplayName();
|
return new ComponentBuilder().append(soldRank.getNextTier(p).getDisplayName()).reset().create();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Material getPriceType(Player p) {
|
public Material getPriceType(Player p) {
|
||||||
@ -41,7 +42,6 @@ public class EnforcedRankedDeal implements Deal {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void commence(Player p) {
|
public void commence(Player p) {
|
||||||
p.sendMessage(String.format("§rYou just purchased %s.", getDealName(p)));
|
|
||||||
soldRank.increasePlayerTier(p, soldRank.getNextTier(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.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
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 {
|
public class ItemDeal implements Deal {
|
||||||
private ItemStack item;
|
private ItemStack item;
|
||||||
@ -32,11 +28,14 @@ public class ItemDeal implements Deal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IChatBaseComponent getDealName(Player p) {
|
public BaseComponent[] getDealName(Player p) {
|
||||||
// BaseComponent.
|
ComponentBuilder builder = new ComponentBuilder()
|
||||||
// new ComponentBuilder().color(ChatColor.WHITE).append(Integer.toString(item.getAmount())).append( Utility.getItemName(item));
|
.append(Integer.toString(item.getAmount()))
|
||||||
// String.format("§r%dx %s%s", item.getAmount(), Utility.getItemName(item), implemented ? "" : " §4§l(not implemented)§r");
|
.color(ChatColor.WHITE)
|
||||||
return new ChatComponentText("none lol");
|
.append("x ")
|
||||||
|
.append(Utility.getItemName(item));
|
||||||
|
if (!implemented) builder.append(" (not implemented)").bold(true).color(ChatColor.RED);
|
||||||
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,7 +58,6 @@ public class ItemDeal implements Deal {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ItemStack item = getDealItem(p);
|
ItemStack item = getDealItem(p);
|
||||||
p.sendMessage(String.format("You just purchased %s.", getDealName(p)));
|
|
||||||
ItemStack[] contents = p.getInventory().getContents();
|
ItemStack[] contents = p.getInventory().getContents();
|
||||||
InventoryUtility.giveItem(contents, item);
|
InventoryUtility.giveItem(contents, item);
|
||||||
p.getInventory().setContents(contents);
|
p.getInventory().setContents(contents);
|
||||||
|
@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import me.topchetoeu.bedwars.Utility;
|
import me.topchetoeu.bedwars.Utility;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
|
||||||
public class RankTier {
|
public class RankTier {
|
||||||
private String name;
|
private String name;
|
||||||
@ -17,8 +19,8 @@ public class RankTier {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
public String getDisplayName() {
|
public BaseComponent[] getDisplayName() {
|
||||||
return Utility.getItemName(icon);
|
return new ComponentBuilder().append(Utility.getItemName(icon)).reset().create();
|
||||||
}
|
}
|
||||||
public ItemStack getIcon() {
|
public ItemStack getIcon() {
|
||||||
return icon;
|
return icon;
|
||||||
|
@ -7,6 +7,8 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import me.topchetoeu.bedwars.Utility;
|
import me.topchetoeu.bedwars.Utility;
|
||||||
import me.topchetoeu.bedwars.engine.Game;
|
import me.topchetoeu.bedwars.engine.Game;
|
||||||
import me.topchetoeu.bedwars.engine.trader.Deal;
|
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 {
|
public class RankedDeal implements Deal {
|
||||||
private Rank soldRank;
|
private Rank soldRank;
|
||||||
@ -29,8 +31,8 @@ public class RankedDeal implements Deal {
|
|||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getDealName(Player p) {
|
public BaseComponent[] getDealName(Player p) {
|
||||||
return Utility.getItemName(soldTier.getIcon());
|
return new ComponentBuilder().append(Utility.getItemName(soldTier.getIcon())).reset().create();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Material getPriceType(Player p) {
|
public Material getPriceType(Player p) {
|
||||||
@ -46,7 +48,6 @@ public class RankedDeal implements Deal {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void commence(Player p) {
|
public void commence(Player p) {
|
||||||
p.sendMessage(String.format("§rYou just purchased %s.", getDealName(p)));
|
|
||||||
soldRank.increasePlayerTier(p, soldTier);
|
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.Team;
|
||||||
import me.topchetoeu.bedwars.engine.trader.Deal;
|
import me.topchetoeu.bedwars.engine.trader.Deal;
|
||||||
import me.topchetoeu.bedwars.engine.trader.upgrades.TeamUpgrade;
|
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 {
|
public class RankedUpgradeDeal implements Deal {
|
||||||
private TeamUpgradeRank rank;
|
private TeamUpgradeRank rank;
|
||||||
@ -43,12 +46,12 @@ public class RankedUpgradeDeal implements Deal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDealName(Player p) {
|
public BaseComponent[] getDealName(Player p) {
|
||||||
if (!Game.isStarted()) return "None";
|
if (!Game.isStarted()) return new BaseComponent[] { new TextComponent("???") };
|
||||||
Team t = Game.instance.getTeam(p);
|
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
|
@Override
|
||||||
|
@ -68,7 +68,6 @@ public class SharpnessTeamUpgrade implements TeamUpgrade {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return getName();
|
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