managers, commands shit

This commit is contained in:
Trixkz 2021-11-21 09:50:15 -05:00
parent 6dcc92da42
commit 4e54849ae4
17 changed files with 614 additions and 14 deletions

View File

@ -3,23 +3,55 @@
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="BranchesTreeState">
<expand>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
</path>
</expand>
<select />
</component>
<component name="ChangeListManager">
<list default="true" id="5f649e9a-d936-4370-9e5c-062bcd7995b7" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/mongo/MongoManager.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/player/PlayerData.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/player/PlayerDataHandler.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/player/PlayerDataManager.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/player/PlayerState.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/player/PlayerTeam.java" afterDir="false" />
<list default="true" id="998d5e92-ac1f-4423-8aef-5f389ab213de" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/BaseCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/AddCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/LevelCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/RemoveCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/level/SetCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/setspawn/SetSpawnCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/setspawn/SpawnCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/AddCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/RemoveCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/SetCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands/xp/XpCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/listeners/RandomListeners.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/managers/CommandManager.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/BedWars.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/BedWars.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/config.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/config.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/plugin.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/plugin.yml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
@ -39,17 +71,18 @@
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/main/java/rip/tilly/bedwars/commands" />
<property name="settings.editor.selected.configurable" value="MTConfigurable" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Luca\Documents\GitHub\BedWars\src\main\java\rip\tilly\bedwars" />
</key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="rip.tilly.bedwars.mongo" />
<recent name="rip.tilly.bedwars.utils" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\logan\Documents\GitHub\BedWars\src\main\java\rip\tilly\bedwars\commands" />
<recent name="C:\Users\Luca\Documents\GitHub\BedWars\src\main\java\rip\tilly\bedwars" />
</key>
</component>
<component name="RunManager">
<configuration name="BedWars build" type="MavenRunConfiguration" factoryName="Maven">
@ -65,7 +98,6 @@
<option name="outputLevel" value="INFO" />
<option name="pluginUpdatePolicy" value="DEFAULT" />
<option name="printErrorStackTraces" value="false" />
<option name="showDialogWithAdvancedSettings" value="false" />
<option name="threads" />
<option name="usePluginRegistry" value="false" />
<option name="userSettingsFile" value="" />

View File

@ -7,6 +7,7 @@ import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.plugin.java.JavaPlugin;
import rip.tilly.bedwars.listeners.RandomListeners;
import rip.tilly.bedwars.mongo.MongoManager;
import rip.tilly.bedwars.player.PlayerDataHandler;
import rip.tilly.bedwars.player.PlayerDataManager;
@ -29,6 +30,7 @@ public final class BedWars extends JavaPlugin {
@Override
public void onEnable() {
instance = this;
this.saveDefaultConfig();
Bukkit.getConsoleSender().sendMessage("------------------------------------------------");
@ -76,7 +78,8 @@ public final class BedWars extends JavaPlugin {
private void loadListeners() {
Arrays.asList(
new PlayerDataHandler()
new PlayerDataHandler(),
new RandomListeners()
).forEach(listener -> this.getServer().getPluginManager().registerEvents(listener, this));
}
}

View File

@ -0,0 +1,14 @@
package rip.tilly.bedwars.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.List;
public abstract class BaseCommand {
public abstract void executeAs(CommandSender sender, Command cmd, String label, String[] args);
public abstract List<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args);
}

View File

@ -0,0 +1,49 @@
package rip.tilly.bedwars.commands.level;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.commands.BaseCommand;
import rip.tilly.bedwars.player.PlayerData;
import rip.tilly.bedwars.utils.CC;
import java.util.ArrayList;
import java.util.List;
public class AddCommand extends BaseCommand {
private BedWars main = BedWars.getInstance();
@Override
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
Player target = this.main.getServer().getPlayer(args[1]);
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
if (!target.isOnline()) {
player.sendMessage(CC.translate("&cError: Player is not currently online"));
return;
}
if (!CC.isNumeric(args[2])) {
player.sendMessage(CC.translate("&cError: Please send a valid number"));
return;
}
Integer amount = Integer.parseInt(args[2]);
playerData.setLevel(playerData.getLevel() + amount);
}
@Override
public List<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -0,0 +1,52 @@
package rip.tilly.bedwars.commands.level;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.trixkz.bedwarspractice.Main;
import xyz.trixkz.bedwarspractice.utils.Utils;
public class LevelCommand implements CommandExecutor {
private Main main;
public LevelCommand(Main main) {
this.main = main;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
if (!player.hasPermission(Utils.ADMIN_PERMISSION_NODE)) {
player.sendMessage(Utils.translate(Utils.NO_PERMISSION_MESSAGE));
return true;
}
if (args.length == 0) {
player.sendMessage(Utils.translate("&cUsage:"));
player.sendMessage(Utils.translate(" &c/level"));
player.sendMessage(Utils.translate(" &c/level set <player> <amount>"));
player.sendMessage(Utils.translate(" &c/level add <player> <amount>"));
player.sendMessage(Utils.translate(" &c/level remove <player> <amount>"));
} else {
switch (args[0]) {
case "set":
new SetCommand(this.main).executeAs(sender, cmd, label, args);
break;
case "add":
new AddCommand(this.main).executeAs(sender, cmd, label, args);
break;
case "remove":
new RemoveCommand(this.main).executeAs(sender, cmd, label, args);
break;
}
}
return true;
}
}

View File

@ -0,0 +1,52 @@
package rip.tilly.bedwars.commands.level;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.player.PlayerData;
import rip.tilly.bedwars.utils.CC;
import xyz.trixkz.bedwarspractice.Main;
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
import xyz.trixkz.bedwarspractice.managers.user.User;
import xyz.trixkz.bedwarspractice.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class RemoveCommand extends BaseCommand {
private BedWars main = BedWars.getInstance();
@Override
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
Player target = this.main.getServer().getPlayer(args[1]);
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
if (!target.isOnline()) {
player.sendMessage(CC.translate("&cError: Player is not currently online"));
return;
}
if (!CC.isNumeric(args[2])) {
player.sendMessage(CC.translate("&cError: Please send a valid number"));
return;
}
Integer amount = Integer.parseInt(args[2]);
playerData.setLevel(playerData.getLevel() - amount);
}
@Override
public List<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -0,0 +1,53 @@
package rip.tilly.bedwars.commands.level;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.trixkz.bedwarspractice.Main;
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
import xyz.trixkz.bedwarspractice.managers.user.User;
import xyz.trixkz.bedwarspractice.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class SetCommand extends BaseCommand {
private Main main;
public SetCommand(Main main) {
this.main = main;
}
@Override
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
Player target = this.main.getServer().getPlayer(args[1]);
User user = User.getByUUID(target.getUniqueId());
if (!target.isOnline()) {
player.sendMessage(Utils.translate("&cError: Player is not currently online"));
return;
}
if (!this.main.getUtils().isNumeric(args[2])) {
player.sendMessage(Utils.translate("&cError: Please send a valid number"));
return;
}
Integer amount = Integer.parseInt(args[2]);
user.getSettings().setLevel(amount);
}
@Override
public List<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -0,0 +1,40 @@
package rip.tilly.bedwars.commands.setspawn;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.utils.CC;
public class SetSpawnCommand implements CommandExecutor {
private BedWars main = BedWars.getInstance();
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
if (!player.hasPermission("bedwars.admin")) {
player.sendMessage(CC.translate("&cNo permission"));
return true;
}
if (args.length == 0) {
player.sendMessage(CC.translate("&cUsage:"));
player.sendMessage(CC.translate(" &c/setspawn spawn"));
player.sendMessage(CC.translate(" &c/setspawn holograms"));
} else {
switch (args[0]) {
case "spawn":
new SpawnCommand().executeAs(sender, cmd, label, args);
break;
case "holograms":
break;
}
}
return true;
}
}

View File

@ -0,0 +1,38 @@
package rip.tilly.bedwars.commands.setspawn;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.utils.CC;
import java.util.ArrayList;
import java.util.List;
public class SpawnCommand extends BaseCommand {
private BedWars main = BedWars.getInstance();
@Override
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
Location location = player.getLocation();
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
player.getWorld().setSpawnLocation(x, y, z);
player.sendMessage(CC.translate("&aSpawn point set"));
}
@Override
public List<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -0,0 +1,53 @@
package rip.tilly.bedwars.commands.xp;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.trixkz.bedwarspractice.Main;
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
import xyz.trixkz.bedwarspractice.managers.user.User;
import xyz.trixkz.bedwarspractice.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class AddCommand extends BaseCommand {
private Main main;
public AddCommand(Main main) {
this.main = main;
}
@Override
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
Player target = this.main.getServer().getPlayer(args[1]);
User user = User.getByUUID(target.getUniqueId());
if (!target.isOnline()) {
player.sendMessage(Utils.translate("&cError: Player is not currently online"));
return;
}
if (!this.main.getUtils().isNumeric(args[2])) {
player.sendMessage(Utils.translate("&cError: Please send a valid number"));
return;
}
Double amount = Double.parseDouble(args[2]);
user.getSettings().addXp(target, amount);
}
@Override
public List<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -0,0 +1,53 @@
package rip.tilly.bedwars.commands.xp;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.trixkz.bedwarspractice.Main;
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
import xyz.trixkz.bedwarspractice.managers.user.User;
import xyz.trixkz.bedwarspractice.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class RemoveCommand extends BaseCommand {
private Main main;
public RemoveCommand(Main main) {
this.main = main;
}
@Override
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
Player target = this.main.getServer().getPlayer(args[1]);
User user = User.getByUUID(target.getUniqueId());
if (!target.isOnline()) {
player.sendMessage(Utils.translate("&cError: Player is not currently online"));
return;
}
if (!this.main.getUtils().isNumeric(args[2])) {
player.sendMessage(Utils.translate("&cError: Please send a valid number"));
return;
}
Double amount = Double.parseDouble(args[2]);
user.getSettings().removeXp(amount);
}
@Override
public List<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -0,0 +1,53 @@
package rip.tilly.bedwars.commands.xp;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.trixkz.bedwarspractice.Main;
import xyz.trixkz.bedwarspractice.commands.BaseCommand;
import xyz.trixkz.bedwarspractice.managers.user.User;
import xyz.trixkz.bedwarspractice.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class SetCommand extends BaseCommand {
private Main main;
public SetCommand(Main main) {
this.main = main;
}
@Override
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
Player target = this.main.getServer().getPlayer(args[1]);
User user = User.getByUUID(target.getUniqueId());
if (!target.isOnline()) {
player.sendMessage(Utils.translate("&cError: Player is not currently online"));
return;
}
if (!this.main.getUtils().isNumeric(args[2])) {
player.sendMessage(Utils.translate("&cError: Please send a valid number"));
return;
}
Double amount = Double.parseDouble(args[2]);
user.getSettings().setXp(amount);
}
@Override
public List<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
List<String> tabCompletions = new ArrayList<String>();
return tabCompletions;
}
}

View File

@ -0,0 +1,52 @@
package rip.tilly.bedwars.commands.xp;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.trixkz.bedwarspractice.Main;
import xyz.trixkz.bedwarspractice.utils.Utils;
public class XpCommand implements CommandExecutor {
private Main main;
public XpCommand(Main main) {
this.main = main;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
if (!player.hasPermission(Utils.ADMIN_PERMISSION_NODE)) {
player.sendMessage(Utils.translate(Utils.NO_PERMISSION_MESSAGE));
return true;
}
if (args.length == 0) {
player.sendMessage(Utils.translate("&cUsage:"));
player.sendMessage(Utils.translate(" &c/xp"));
player.sendMessage(Utils.translate(" &c/xp set <player> <amount>"));
player.sendMessage(Utils.translate(" &c/xp add <player> <amount>"));
player.sendMessage(Utils.translate(" &c/xp remove <player> <amount>"));
} else {
switch (args[0]) {
case "set":
new SetCommand(this.main).executeAs(sender, cmd, label, args);
break;
case "add":
new AddCommand(this.main).executeAs(sender, cmd, label, args);
break;
case "remove":
new RemoveCommand(this.main).executeAs(sender, cmd, label, args);
break;
}
}
return true;
}
}

View File

@ -0,0 +1,28 @@
package rip.tilly.bedwars.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
public class RandomListeners implements Listener {
@EventHandler
public void onFoodLevelChange(FoodLevelChangeEvent event) {
event.setCancelled(true);
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
// event.setCancelled(true);
// to do
// only be able to drop an item when the player is in a game
}
@EventHandler
public void onWeatherChange(WeatherChangeEvent event) {
event.setCancelled(true);
}
}

View File

@ -0,0 +1,17 @@
package rip.tilly.bedwars.managers;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.commands.setspawn.SetSpawnCommand;
public class CommandManager {
private BedWars main = BedWars.getInstance();
public CommandManager() {
this.registerCommands();
}
private void registerCommands() {
this.main.getCommand("setspawn").setExecutor(new SetSpawnCommand());
}
}

View File

@ -35,4 +35,12 @@ public class CC {
}
return strings;
}
public static boolean isNumeric(String string) {
return regexNumeric(string).length() == 0;
}
public static String regexNumeric(String string) {
return string.replaceAll("[0-9]", "").replaceFirst("\\.", "");
}
}

View File

@ -4,3 +4,6 @@ main: rip.tilly.bedwars.BedWars
authors:
- Lucanius
- Trixkz
commands:
setspawn: