players, final Object packet) {
- try {
- for (final String name : players) {
- final Object nmsPlayer = getNmsPlayer(Bukkit.getPlayer(name));
- final Object connection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
- connection.getClass().getMethod("sendPacket", getClass("{nms}.Packet")).invoke(connection, packet);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
-
- public static void sendPlayerPacket(final Player p, final Object packet) throws Exception {
- final Object nmsPlayer = getNmsPlayer(p);
- final Object connection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
- connection.getClass().getMethod("sendPacket", getClass("{nms}.Packet")).invoke(connection, packet);
- }
-}
diff --git a/src/main/java/eu/univento/core/api/AutoCommand.java b/src/main/java/eu/univento/core/api/AutoCommand.java
index d50368e..b31248f 100644
--- a/src/main/java/eu/univento/core/api/AutoCommand.java
+++ b/src/main/java/eu/univento/core/api/AutoCommand.java
@@ -1,6 +1,5 @@
package eu.univento.core.api;
-import eu.univento.core.Core;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
@@ -17,6 +16,7 @@ import java.util.List;
* @see "http://postcrafter.de/viewtopic.php?f=15&t=143"
* @param main class
*/
+@Deprecated
public abstract class AutoCommand
extends Command {
private static String VERSION;
@@ -24,7 +24,7 @@ public abstract class AutoCommand
extends Command {
static {
String path = Bukkit.getServer().getClass().getPackage().getName();
AutoCommand.VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
- Core.getCommons().getLoggingHandler().getCore().info("AutoCommand hook for Bukkit " + AutoCommand.VERSION);
+ System.out.println("AutoCommand hook for Bukkit " + AutoCommand.VERSION);
}
private final P plugin;
diff --git a/src/main/java/eu/univento/core/api/Utils.java b/src/main/java/eu/univento/core/api/Utils.java
index a10adae..794a1be 100644
--- a/src/main/java/eu/univento/core/api/Utils.java
+++ b/src/main/java/eu/univento/core/api/Utils.java
@@ -168,20 +168,10 @@ public class Utils {
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), () -> {
if(Core.getOnlinePlayers().size() != 0) {
for(CustomPlayer players : Core.getOnlinePlayers())
+ //TODO: add connect to optimal lobby server here
players.connectToServer("Lobby01");
}
Bukkit.spigot().restart();
}, 10 * 20L);
}
-
- /**
- * shots random firework at specified location
- *
- * @param loc Location
- */
- public static void randomFirework(Location loc) {
- FireworkEffect.Builder builder = FireworkEffect.builder();
- FireworkEffect effect = builder.flicker(false).trail(false).with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withFade(Color.BLUE).build();
- //TODO: make a random fireworks effect
- }
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/command/BukkitCommand.java b/src/main/java/eu/univento/core/api/command/BukkitCommand.java
new file mode 100644
index 0000000..fb1b2f9
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/command/BukkitCommand.java
@@ -0,0 +1,96 @@
+package eu.univento.core.api.command;
+
+import org.apache.commons.lang3.Validate;
+import org.bukkit.command.CommandException;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.bukkit.plugin.Plugin;
+
+import java.util.List;
+
+/**
+ * Command Framework - BukkitCommand
+ * An implementation of Bukkit's Command class allowing for registering of
+ * commands without plugin.yml
+ *
+ * @author minnymin3
+ *
+ */
+public class BukkitCommand extends org.bukkit.command.Command {
+
+ private final Plugin owningPlugin;
+ private CommandExecutor executor;
+ protected BukkitCompleter completer;
+
+ /**
+ * A slimmed down PluginCommand
+ */
+ protected BukkitCommand(String label, CommandExecutor executor, Plugin owner) {
+ super(label);
+ this.executor = executor;
+ this.owningPlugin = owner;
+ this.usageMessage = "";
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String commandLabel, String[] args) {
+ boolean success;
+
+ if (!owningPlugin.isEnabled()) {
+ return false;
+ }
+
+ if (!testPermission(sender)) {
+ return true;
+ }
+
+ try {
+ success = executor.onCommand(sender, this, commandLabel, args);
+ } catch (Throwable ex) {
+ throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin "
+ + owningPlugin.getDescription().getFullName(), ex);
+ }
+
+ if (!success && usageMessage.length() > 0) {
+ for (String line : usageMessage.replace("", commandLabel).split("\n")) {
+ sender.sendMessage(line);
+ }
+ }
+
+ return success;
+ }
+
+ @Override
+ public java.util.List tabComplete(CommandSender sender, String alias, String[] args)
+ throws CommandException, IllegalArgumentException {
+ Validate.notNull(sender, "Sender cannot be null");
+ Validate.notNull(args, "Arguments cannot be null");
+ Validate.notNull(alias, "Alias cannot be null");
+
+ List completions = null;
+ try {
+ if (completer != null) {
+ completions = completer.onTabComplete(sender, this, alias, args);
+ }
+ if (completions == null && executor instanceof TabCompleter) {
+ completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
+ }
+ } catch (Throwable ex) {
+ StringBuilder message = new StringBuilder();
+ message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
+ for (String arg : args) {
+ message.append(arg).append(' ');
+ }
+ message.deleteCharAt(message.length() - 1).append("' in plugin ")
+ .append(owningPlugin.getDescription().getFullName());
+ throw new CommandException(message.toString(), ex);
+ }
+
+ if (completions == null) {
+ return super.tabComplete(sender, alias, args);
+ }
+ return completions;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/command/BukkitCompleter.java b/src/main/java/eu/univento/core/api/command/BukkitCompleter.java
new file mode 100644
index 0000000..847d77f
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/command/BukkitCompleter.java
@@ -0,0 +1,49 @@
+package eu.univento.core.api.command;
+
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.AbstractMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Command Framework - BukkitCompleter
+ * An implementation of the TabCompleter class allowing for multiple tab
+ * completers per command
+ *
+ * @author minnymin3
+ *
+ */
+public class BukkitCompleter implements TabCompleter {
+
+ private Map> completers = new HashMap<>();
+
+ public void addCompleter(String label, Method m, Object obj) {
+ completers.put(label, new AbstractMap.SimpleEntry<>(m, obj));
+ }
+
+ @Override
+ public List onTabComplete(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
+ for (int i = args.length; i >= 0; i--) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(label.toLowerCase());
+ for (int x = 0; x < i; x++) {
+ if (!args[x].equals("") && !args[x].equals(" ")) buffer.append(".").append(args[x].toLowerCase());
+ }
+ String cmdLabel = buffer.toString();
+ if (completers.containsKey(cmdLabel)) {
+ Map.Entry entry = completers.get(cmdLabel);
+ try {
+ return (List) entry.getKey().invoke(entry.getValue(), new CommandArgs(sender, command, label, args, cmdLabel.split("\\.").length - 1));
+ } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return null;
+ }
+ }
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/command/Command.java b/src/main/java/eu/univento/core/api/command/Command.java
new file mode 100644
index 0000000..9661ce7
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/command/Command.java
@@ -0,0 +1,79 @@
+package eu.univento.core.api.command;
+
+import eu.univento.commons.player.rank.Group;
+import eu.univento.commons.player.rank.Rank;
+import eu.univento.commons.server.ServerType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Command Framework - Command
+ * The command annotation used to designate methods as commands. All methods
+ * should have a single CommandArgs argument
+ *
+ * @author minnymin3, joethei
+ *
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Command {
+
+ /**
+ * The name of the command. If it is a sub command then its values would be
+ * separated by periods. ie. a command that would be a subcommand of test
+ * would be 'test.subcommandname'
+ *
+ * @return
+ */
+ public String name();
+
+ /**
+ * Gets the required permission of the command
+ *
+ * @return
+ */
+ public Rank rank() default Rank.Player;
+ public Group group() default Group.None;
+
+ public ServerType serverType() default ServerType.NONE;
+
+ /**
+ * The message sent to the player when they do not have permission to
+ * execute it
+ *
+ * @return
+ */
+ public String notAllowed() default "§cYou do not have permission to perform that action";
+
+ /**
+ * A list of alternate names that the command is executed under. See
+ * name() for details on how names work
+ *
+ * @return
+ */
+ public String[] aliases() default {};
+
+ /**
+ * The description that will appear in /help of the command
+ *
+ * @return
+ */
+ public String description() default "";
+
+ /**
+ * The usage that will appear in /help (commandname)
+ *
+ * @return
+ */
+ public String usage() default "";
+
+ /**
+ * Whether or not the command is available to players only
+ *
+ * @return
+ */
+ public boolean inGameOnly() default false;
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/command/CommandArgs.java b/src/main/java/eu/univento/core/api/command/CommandArgs.java
new file mode 100644
index 0000000..a0dd75f
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/command/CommandArgs.java
@@ -0,0 +1,108 @@
+package eu.univento.core.api.command;
+
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+/**
+ * Command Framework - CommandArgs
+ * This class is passed to the command methods and contains various utilities as
+ * well as the command info.
+ *
+ * @author minnymin3
+ *
+ */
+public class CommandArgs {
+
+ private CommandSender sender;
+ private org.bukkit.command.Command command;
+ private String label;
+ private String[] args;
+
+ protected CommandArgs(CommandSender sender, org.bukkit.command.Command command, String label, String[] args,
+ int subCommand) {
+ String[] modArgs = new String[args.length - subCommand];
+ for (int i = 0; i < args.length - subCommand; i++) {
+ modArgs[i] = args[i + subCommand];
+ }
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(label);
+ for (int x = 0; x < subCommand; x++) {
+ buffer.append("." + args[x]);
+ }
+ String cmdLabel = buffer.toString();
+ this.sender = sender;
+ this.command = command;
+ this.label = cmdLabel;
+ this.args = modArgs;
+ }
+
+ /**
+ * Gets the command sender
+ *
+ * @return
+ */
+ public CommandSender getSender() {
+ return sender;
+ }
+
+ /**
+ * Gets the original command object
+ *
+ * @return
+ */
+ public org.bukkit.command.Command getCommand() {
+ return command;
+ }
+
+ /**
+ * Gets the label including sub command labels of this command
+ *
+ * @return Something like 'test.subcommand'
+ */
+ public String getLabel() {
+ return label;
+ }
+
+ /**
+ * Gets all the arguments after the command's label. ie. if the command
+ * label was test.subcommand and the arguments were subcommand foo foo, it
+ * would only return 'foo foo' because 'subcommand' is part of the command
+ *
+ * @return
+ */
+ public String[] getArgs() {
+ return args;
+ }
+
+ /**
+ * Gets the argument at the specified index
+ * @param index The index to get
+ * @return The string at the specified index
+ */
+ public String getArg(int index) {
+ return args[index];
+ }
+
+ /**
+ * Returns the length of the command arguments
+ * @return int length of args
+ */
+ public int length() {
+ return args.length;
+ }
+
+ public boolean isPlayer() {
+ return sender instanceof Player;
+ }
+
+ public CustomPlayer getPlayer() {
+ if (sender instanceof Player) {
+ return CustomPlayer.getPlayer((Player) sender);
+ } else {
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/command/CommandFramework.java b/src/main/java/eu/univento/core/api/command/CommandFramework.java
new file mode 100644
index 0000000..857a3cd
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/command/CommandFramework.java
@@ -0,0 +1,220 @@
+package eu.univento.core.api.command;
+
+import eu.univento.commons.player.rank.Group;
+import eu.univento.commons.player.rank.Rank;
+import eu.univento.commons.server.ServerType;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandMap;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.PluginCommand;
+import org.bukkit.entity.Player;
+import org.bukkit.help.GenericCommandHelpTopic;
+import org.bukkit.help.HelpTopic;
+import org.bukkit.help.HelpTopicComparator;
+import org.bukkit.help.IndexHelpTopic;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.SimplePluginManager;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.*;
+
+/**
+ * Command Framework - CommandFramework
+ * The main command framework class used for controlling the framework.
+ *
+ * @author minnymin3
+ */
+public class CommandFramework implements CommandExecutor {
+
+ private Map> commandMap = new HashMap<>();
+ private CommandMap map;
+ private Plugin plugin;
+
+ /**
+ * Initializes the command framework and sets up the command maps
+ */
+ public CommandFramework(Plugin plugin) {
+ this.plugin = plugin;
+ if (plugin.getServer().getPluginManager() instanceof SimplePluginManager) {
+ SimplePluginManager manager = (SimplePluginManager) plugin.getServer().getPluginManager();
+ try {
+ Field field = SimplePluginManager.class.getDeclaredField("commandMap");
+ field.setAccessible(true);
+ map = (CommandMap) field.get(manager);
+ } catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
+ return handleCommand(sender, cmd, label, args);
+ }
+
+ /**
+ * Handles commands. Used in the onCommand method in your JavaPlugin class
+ *
+ * @param sender The {@link org.bukkit.command.CommandSender} parsed from
+ * onCommand
+ * @param cmd The {@link org.bukkit.command.Command} parsed from onCommand
+ * @param label The label parsed from onCommand
+ * @param args The arguments parsed from onCommand
+ * @return Always returns true for simplicity's sake in onCommand
+ */
+ public boolean handleCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
+ for (int i = args.length; i >= 0; i--) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(label.toLowerCase());
+ for (int x = 0; x < i; x++) {
+ buffer.append(".").append(args[x].toLowerCase());
+ }
+ String cmdLabel = buffer.toString();
+ if (commandMap.containsKey(cmdLabel)) {
+ Method method = commandMap.get(cmdLabel).getKey();
+ Object methodObject = commandMap.get(cmdLabel).getValue();
+ Command command = method.getAnnotation(Command.class);
+ CustomPlayer player = CustomPlayer.getPlayer((Player) sender);
+ if (Objects.equals(command.group(), Group.None) && !Objects.equals(command.rank(), Rank.Player) && !player.getDatabasePlayer().isAllowed(command.rank())) {
+ sender.sendMessage(command.notAllowed());
+ return true;
+ }
+ if (Objects.equals(command.rank(), Rank.Player) && !Objects.equals(command.group(), Group.None) && !player.getDatabasePlayer().isAllowed(command.group())) {
+ sender.sendMessage(command.notAllowed());
+ return true;
+ }
+ if (command.inGameOnly() && sender == null) {
+ sender.sendMessage("This command is only performable in game");
+ return true;
+ }
+ if (command.serverType() != ServerType.NONE && command.serverType() != ServerType.getServerType()) {
+ sender.sendMessage("This command can only be performed on " + command.serverType().getName() + " servers");
+ return true;
+ }
+ try {
+ method.invoke(methodObject, new CommandArgs(sender, cmd, label, args,
+ cmdLabel.split("\\.").length - 1));
+ } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+ }
+ defaultCommand(new CommandArgs(sender, cmd, label, args, 0));
+ return true;
+ }
+
+ /**
+ * Registers all command and completer methods inside of the object. Similar
+ * to Bukkit's registerEvents method.
+ *
+ * @param obj The object to register the commands of
+ */
+ public void registerCommands(Object obj) {
+ for (Method m : obj.getClass().getMethods()) {
+ if (m.getAnnotation(Command.class) != null) {
+ Command command = m.getAnnotation(Command.class);
+ if (m.getParameterTypes().length > 1 || m.getParameterTypes()[0] != CommandArgs.class) {
+ System.out.println("Unable to register command " + m.getName() + ". Unexpected method arguments");
+ continue;
+ }
+ registerCommand(command, command.name(), m, obj);
+ for (String alias : command.aliases()) {
+ registerCommand(command, alias, m, obj);
+ }
+ } else if (m.getAnnotation(Completer.class) != null) {
+ Completer comp = m.getAnnotation(Completer.class);
+ if (m.getParameterTypes().length > 1 || m.getParameterTypes().length == 0
+ || m.getParameterTypes()[0] != CommandArgs.class) {
+ System.out.println("Unable to register tab completer " + m.getName()
+ + ". Unexpected method arguments");
+ continue;
+ }
+ if (m.getReturnType() != List.class) {
+ System.out.println("Unable to register tab completer " + m.getName() + ". Unexpected return type");
+ continue;
+ }
+ registerCompleter(comp.name(), m, obj);
+ for (String alias : comp.aliases()) {
+ registerCompleter(alias, m, obj);
+ }
+ }
+ }
+ }
+
+ /**
+ * Registers all the commands under the plugin's help
+ */
+ public void registerHelp() {
+ Set help = new TreeSet<>(HelpTopicComparator.helpTopicComparatorInstance());
+ for (String s : commandMap.keySet()) {
+ if (!s.contains(".")) {
+ org.bukkit.command.Command cmd = map.getCommand(s);
+ HelpTopic topic = new GenericCommandHelpTopic(cmd);
+ help.add(topic);
+ }
+ }
+ IndexHelpTopic topic = new IndexHelpTopic(plugin.getName(), "All commands for " + plugin.getName(), null, help,
+ "Below is a list of all " + plugin.getName() + " commands:");
+ Bukkit.getServer().getHelpMap().addTopic(topic);
+ }
+
+ public void registerCommand(Command command, String label, Method m, Object obj) {
+ commandMap.put(label.toLowerCase(), new AbstractMap.SimpleEntry<>(m, obj));
+ commandMap.put(this.plugin.getName() + ':' + label.toLowerCase(), new AbstractMap.SimpleEntry<>(m, obj));
+ String cmdLabel = label.split("\\.")[0].toLowerCase();
+ if (map.getCommand(cmdLabel) == null) {
+ org.bukkit.command.Command cmd = new BukkitCommand(cmdLabel, this, plugin);
+ map.register(plugin.getName(), cmd);
+ }
+ if (!command.description().equalsIgnoreCase("") && Objects.equals(cmdLabel, label)) {
+ map.getCommand(cmdLabel).setDescription(command.description());
+ }
+ if (!command.usage().equalsIgnoreCase("") && Objects.equals(cmdLabel, label)) {
+ map.getCommand(cmdLabel).setUsage(command.usage());
+ }
+ }
+
+ public void registerCompleter(String label, Method m, Object obj) {
+ String cmdLabel = label.split("\\.")[0].toLowerCase();
+ if (map.getCommand(cmdLabel) == null) {
+ org.bukkit.command.Command command = new BukkitCommand(cmdLabel, this, plugin);
+ map.register(plugin.getName(), command);
+ }
+ if (map.getCommand(cmdLabel) instanceof BukkitCommand) {
+ BukkitCommand command = (BukkitCommand) map.getCommand(cmdLabel);
+ if (command.completer == null) {
+ command.completer = new BukkitCompleter();
+ }
+ command.completer.addCompleter(label, m, obj);
+ } else if (map.getCommand(cmdLabel) instanceof PluginCommand) {
+ try {
+ Object command = map.getCommand(cmdLabel);
+ Field field = command.getClass().getDeclaredField("completer");
+ field.setAccessible(true);
+ if (field.get(command) == null) {
+ BukkitCompleter completer = new BukkitCompleter();
+ completer.addCompleter(label, m, obj);
+ field.set(command, completer);
+ } else if (field.get(command) instanceof BukkitCompleter) {
+ BukkitCompleter completer = (BukkitCompleter) field.get(command);
+ completer.addCompleter(label, m, obj);
+ } else {
+ System.out.println("Unable to register tab completer " + m.getName()
+ + ". A tab completer is already registered for that command!");
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private void defaultCommand(CommandArgs args) {
+ args.getSender().sendMessage(args.getLabel() + " is not handled! Oh noes!");
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/command/Completer.java b/src/main/java/eu/univento/core/api/command/Completer.java
new file mode 100644
index 0000000..78bcacb
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/command/Completer.java
@@ -0,0 +1,37 @@
+package eu.univento.core.api.command;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Command Framework - Completer
+ * The completer annotation used to designate methods as command completers. All
+ * methods should have a single CommandArgs argument and return a String List
+ * object
+ *
+ * @author minnymin3
+ *
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Completer {
+
+ /**
+ * The command that this completer completes. If it is a sub command then
+ * its values would be separated by periods. ie. a command that would be a
+ * subcommand of test would be 'test.subcommandname'
+ *
+ * @return
+ */
+ String name();
+
+ /**
+ * A list of alternate names that the completer is executed under. See
+ * name() for details on how names work
+ *
+ * @return
+ */
+ String[] aliases() default {};
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java b/src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java
deleted file mode 100644
index 206f4b7..0000000
--- a/src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java
+++ /dev/null
@@ -1,238 +0,0 @@
-package eu.univento.core.api.fakeplayer;
-
-import com.mojang.authlib.GameProfile;
-import eu.univento.core.Core;
-import net.minecraft.server.v1_11_R1.*;
-import org.bukkit.Location;
-import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
-import org.bukkit.entity.ArmorStand;
-import org.bukkit.entity.EntityType;
-import org.bukkit.entity.LivingEntity;
-import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitRunnable;
-import org.bukkit.scheduler.BukkitTask;
-
-import java.lang.reflect.Field;
-
-/**
- * @author joethei
- * @version 0.3
- */
-public class FakePlayer {
-
- //TODO: fix parts and add some stuff
-
- private static final double MOVE_SPEED = 4.3D / 20;
-
- private final Player player;
- private final int entityId;
- private final GameProfile gameProfile;
- private final DataWatcher dataWatcher;
-
- private Location location;
- private ArmorStand armorStand;
- private LivingEntity target;
- private BukkitTask task;
-
- private final boolean moveable;
-
- public FakePlayer(GameProfile gameProfile, boolean moveable, Player player) {
-
- this.player = player;
-
- this.moveable = moveable;
-
- this.entityId = (int) get(Entity.class, "entityCount");
- set(Entity.class, null, "entityCount", this.entityId + 1);
- this.gameProfile = gameProfile;
-
- this.dataWatcher = new DataWatcher(null);
- byte status = 0;
- //this.dataWatcher.a(0, status);
- //this.dataWatcher.a(10, (byte) 127);
- //this.dataWatcher.a(6, 20F);
- }
-
- public Location getLocation() {
- return location;
- }
-
- public int getEntityID() {
- return entityId;
- }
-
- private final BukkitRunnable tickTask = new BukkitRunnable() {
-
- private int ticksLiving = 0;
-
- @Override
- public void run() {
- if(target != null) {
- followEntity(target);
-
- ticksLiving++;
- }
- }
- };
-
- /*
- private byte changeMask(byte bitMask, int bit, boolean state) {
- if(state)
- return bitMask | 1 << bit;
- else
- return bitMask & ~(1 << bit);
- }
- */
-
- public void setTarget(LivingEntity target) {
- this.target = target;
- }
-
- public void clearTarget() {
- this.target = null;
- }
-
- public void setFire(boolean fire) {
- setStatus(0, fire);
- }
-
- public void setSneaking() {
- setStatus(1, true);
- }
-
- public void setSprinting(boolean sprinting) {
- setStatus(3, sprinting);
- }
-
- public void setUseItem(boolean useItem) {
- setStatus(4, useItem);
- }
-
- public void setInvisible(boolean invisible) {
- setStatus(5, invisible);
- }
-
- private void setStatus(int data, boolean bool) {
- DataWatcher dataWatcher = this.dataWatcher;
- byte status = 0;
- //dataWatcher.a(0, status);
- //dataWatcher.a(10, (byte) 127);
- //dataWatcher.a(6, 20F);
- }
-
- public void followEntity(LivingEntity entity) {
- double diffX = entity.getLocation().getX() - location.getX();
- double diffY = (entity.getLocation().getY() + entity.getEyeHeight() * 0.9D) - location.getY() + 1.6F;
- double diffZ = entity.getLocation().getZ() - location.getZ();
- double hypoXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);
- float yaw = (float) (Math.atan2(diffZ, diffX) * 180D / Math.PI) - 90F;
- float pitch = (float) -(Math.atan2(diffY, hypoXZ) * 18D / Math.PI);
- look(yaw, pitch);
-
- if(moveable) {
- if(Math.abs(diffX) > 3D || Math.abs(diffZ) > 3D) {
- yaw = (float) Math.toRadians(yaw);
- double x = Math.sin(yaw);
- double z = Math.cos(yaw);
- move(x * MOVE_SPEED, z * MOVE_SPEED);
- }
- }
- }
-
- private void move(double x, double z) {
- sendPackets(new PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook(this.entityId, (byte) toFixedPointNumber(x), (byte) toFixedPointNumber(0), (byte) toFixedPointNumber(z), toAngle(location.getYaw()), toAngle(location.getPitch()), true));
- this.location.add(toFixedPointNumber(x) / 32D, toFixedPointNumber(0) / 32D, toFixedPointNumber(z) / 32D);
- this.armorStand.teleport(this.location);
- }
-
- public void spawn(Location location) {
- PacketPlayOutNamedEntitySpawn playerSpawn = new PacketPlayOutNamedEntitySpawn();
- set(playerSpawn, "a", this.entityId);
- set(playerSpawn, "b", this.gameProfile.getId());
- set(playerSpawn, "c", toFixedPointNumber(location.getX()));
- set(playerSpawn, "d", toFixedPointNumber(location.getY()));
- set(playerSpawn, "e", toFixedPointNumber(location.getZ()));
- set(playerSpawn, "f", toAngle(location.getYaw()));
- set(playerSpawn, "g", toAngle(location.getPitch()));
- set(playerSpawn, "h", 0);
- set(playerSpawn, "i", this.dataWatcher);
-
- //XXX: cannot acess PlayerInfoData
- PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
- //set(playerInfo, "b", Collections.singletonList(playerInfo.new PlayerInfoData(this.gameProfile, 0, WorldSettings.EnumGamemode.NOT_SET, new ChatComponentText(this.gameProfile.getName()))));
- sendPackets(playerInfo, playerSpawn);
-
- this.location = location;
- this.armorStand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
- this.armorStand.setGravity(true);
- this.armorStand.setVisible(false);
-
- this.task = tickTask.runTaskTimer(Core.getInstance(), 0L, 1L);
- }
- //XXX: cannot acess PlayerInfoData
- public void despawn() {
- PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
- //set(playerInfo, "b", Collections.singletonList(playerInfo.new PlayerInfoData(this.gameProfile, 0, null, null)));
- sendPackets(new PacketPlayOutEntityDestroy(this.entityId), playerInfo);
-
- this.armorStand.remove();
- this.armorStand = null;
- this.task.cancel();
- }
-
- //XXX: cannot acess PlayerInfoData
- public void removeTablist() {
- PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
- //set(playerInfo, "b", Arrays.asList(playerInfo.new PlayerInfoData(this.gameProfile, 0, null, null)));
- sendPackets(new PacketPlayOutEntityDestroy(this.entityId), playerInfo);
- }
-
-
- private void look(float yaw, float pitch) {
- PacketPlayOutEntityHeadRotation headRotation = new PacketPlayOutEntityHeadRotation();
- set(headRotation, "a", this.entityId);
- set(headRotation, "b", toAngle(yaw));
- sendPackets(headRotation, new PacketPlayOutEntity.PacketPlayOutEntityLook(this.entityId, toAngle(yaw), toAngle(pitch), false));
- this.location.setYaw(yaw);
- this.location.setPitch(pitch);
- }
-
- private int toFixedPointNumber(double value) {
- return (int) Math.floor(value * 32D);
- }
-
- private byte toAngle(float value) {
- return (byte) ((int) (value * 256.0F / 360.F));
- }
-
- private void sendPackets(Packet>... packets) {
- for(Packet> packet : packets)
- ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
- }
-
- private void set(Object instance, String name, Object value) {
- set(instance.getClass(), instance, name, value);
- }
-
- private void set(Class> clazz, Object instance, String name, Object value) {
- try{
- Field field = clazz.getDeclaredField(name);
- field.setAccessible(true);
- field.set(instance, value);
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private Object get(Class> clazz, String name) {
- try{
- Field field = clazz.getDeclaredField("entityCount");
- field.setAccessible(true);
- return field.get(null);
- }catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/fakeplayer/PlayerKi.java b/src/main/java/eu/univento/core/api/fakeplayer/PlayerKi.java
deleted file mode 100644
index 87c88f6..0000000
--- a/src/main/java/eu/univento/core/api/fakeplayer/PlayerKi.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package eu.univento.core.api.fakeplayer;
-
-import com.mojang.authlib.GameProfile;
-import eu.univento.core.api.utils.GameProfileBuilder;
-import org.bukkit.Material;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.block.Action;
-import org.bukkit.event.player.PlayerInteractEvent;
-
-import java.util.UUID;
-
-/**
- * @author joethei
- * @version 0.1
- */
-class PlayerKi implements Listener{
-
- private FakePlayer player;
-
- private FakePlayer createPlayer(Player p, String uuid, String skinUrl, String capeUrl) {
- GameProfile gameProfile = GameProfileBuilder.getProfile(UUID.fromString(uuid), "TestUser", skinUrl, capeUrl);
- return new FakePlayer(gameProfile, true, p);
- }
-
- @EventHandler
- public void onInteract(PlayerInteractEvent e) {
- if(e.getAction() == Action.RIGHT_CLICK_AIR) {
- if(e.getItem().getType() == Material.DIAMOND) {
- if(this.player != null) {
- this.player.despawn();
- }
- FakePlayer player = createPlayer(e.getPlayer(), e.getPlayer().getUniqueId().toString(),
- "http://textures.minecraft.net/texture/a116e69a845e227f7ca1fdde8c357c8c821ebd4ba619382ea4a1f87d4ae94",
- "http://textures.minecraft.net/texture/3f688e0e699b3d9fe448b5bb50a3a288f9c589762b3dae8308842122dcb81");
- this.player = player;
- player.spawn(e.getPlayer().getLocation());
- player.setTarget(e.getPlayer());
- player.setSneaking();
- player.removeTablist();
- }
- if(e.getItem().getType() == Material.DIAMOND_SWORD) {
- player.despawn();
- }
- if(e.getItem().getType() == Material.NETHER_STAR) {
- player.followEntity(e.getPlayer());
- }
- }
- }
-}
diff --git a/src/main/java/eu/univento/core/api/hologram/Hologram.java b/src/main/java/eu/univento/core/api/hologram/Hologram.java
index 81d05d8..bbec925 100644
--- a/src/main/java/eu/univento/core/api/hologram/Hologram.java
+++ b/src/main/java/eu/univento/core/api/hologram/Hologram.java
@@ -13,6 +13,7 @@ import net.minecraft.server.v1_11_R1.EntityArmorStand;
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_11_R1.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import org.bukkit.entity.ArmorStand;
@@ -50,13 +51,22 @@ public class Hologram implements Listener{
}
}
+ public void showAll() {
+ for(CustomPlayer p : Core.getOnlinePlayers()) show(p);
+ }
+
public void hide(CustomPlayer p) {
for(EntityArmorStand stand : stands) {
p.sendPacket(new PacketPlayOutEntityDestroy(stand.getId()));
}
}
+ public void hideAll() {
+ for(CustomPlayer p : Core.getOnlinePlayers()) hide(p);
+ }
+
public void destroy() {
+ hideAll();
for(EntityArmorStand armorStand : stands) {
armorStand.die();
}
@@ -67,7 +77,7 @@ public class Hologram implements Listener{
double DISTANCE = 0.25D;
for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
- entity.setCustomName(text);
+ entity.setCustomName(ChatColor.translateAlternateColorCodes('&', text));
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setNoGravity(true);
diff --git a/src/main/java/eu/univento/core/api/items/ItemBuilder.java b/src/main/java/eu/univento/core/api/items/ItemBuilder.java
index 030f923..c72a5e2 100644
--- a/src/main/java/eu/univento/core/api/items/ItemBuilder.java
+++ b/src/main/java/eu/univento/core/api/items/ItemBuilder.java
@@ -249,6 +249,7 @@ public class ItemBuilder {
meta().addEnchant(Enchantment.ARROW_DAMAGE, 10, false);
return this;
}
+
/**
* Clears the defined {@link String} of lore from the {@link ItemStack}
*
diff --git a/src/main/java/eu/univento/core/api/npc/NPC.java b/src/main/java/eu/univento/core/api/npc/NPC.java
index 3475b2a..5a654b8 100644
--- a/src/main/java/eu/univento/core/api/npc/NPC.java
+++ b/src/main/java/eu/univento/core/api/npc/NPC.java
@@ -2,152 +2,304 @@ package eu.univento.core.api.npc;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
-import eu.univento.commons.player.uuid.UUIDFetcher;
import eu.univento.core.Core;
import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.utils.GameProfileBuilder;
-import lombok.Data;
-import net.minecraft.server.v1_11_R1.DataWatcher;
-import net.minecraft.server.v1_11_R1.PacketPlayOutEntityDestroy;
-import net.minecraft.server.v1_11_R1.PacketPlayOutNamedEntitySpawn;
+import lombok.Getter;
+import net.minecraft.server.v1_11_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.BlockFace;
+import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
+import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
+import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
+import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
+import org.bukkit.entity.*;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.bukkit.scheduler.BukkitTask;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.UUID;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import eu.univento.core.api.npc.NPC;
/**
- * @author joethei
- * @version 0.1
+ * @author Ploxh4D, joethei
+ * @version 1.0
*/
+public class NPC extends EntityPlayer {
-@Data
-public class NPC{
+ @Getter private static List npcs = new LinkedList<>();
- private int entityID;
- private Location location;
- private static GameProfile gameProfile;
- private DataWatcher dataWatcher;
+ public static NPC spawn(CustomPlayer p, GameProfile profile, Location location) {
+ GameProfile npcProfile = new GameProfile(profile.getId(), profile.getName());
+ for(Map.Entry properties : profile.getProperties().entries()) npcProfile.getProperties().put(properties.getKey(), properties.getValue());
+ NPC npc = new NPC(((CraftServer)Bukkit.getServer()).getServer(), ((CraftWorld)p.getWorld()).getHandle(), npcProfile, new PlayerInteractManager(((CraftWorld)p.getWorld()).getHandle()), p, location.getBlockX(), location.getBlockZ());
+ npcProfile.getProperties().put("npc", new Property("npc", "npc"));
+ npcs.add(npc);
+ return npc;
+ }
- public NPC(String name, Location location) {
- this.location = location;
- dataWatcher = new DataWatcher(null);
- gameProfile = new GameProfile(UUID.randomUUID(), name);
- entityID = (int) (Math.ceil(Math.random() * 1000) + 2000);
- Bukkit.getScheduler().scheduleAsyncDelayedTask(Core.getInstance(), () -> {
- try {
- gameProfile = GameProfileBuilder.fetch(UUIDFetcher.getRequest(name));
- } catch (IOException e) {
- e.printStackTrace();
+ public CustomPlayer detect;
+ public PacketPlayOutNamedEntitySpawn packet;
+ public int x;
+ public int z;
+ public String message;
+ public EntityPlayer player;
+ private BukkitTask task;
+
+ public NPC(final MinecraftServer minecraftserver, final WorldServer worldserver, final GameProfile gameprofile, final PlayerInteractManager playerinteractmanager, final Player player, final int x, final int z) {
+ super(minecraftserver, worldserver, gameprofile, playerinteractmanager);
+ CustomPlayer p = CustomPlayer.getPlayer(player);
+ this.detect = null;
+ this.x = 0;
+ this.z = 0;
+ this.message = "";
+ this.detect = p;
+ this.x = x;
+ this.z = z;
+ try {
+ final NetworkManager netManager = new NPCNetworkManager(EnumProtocolDirection.SERVERBOUND);
+ netManager.setPacketListener(this.playerConnection = new NPCPlayerConnection(((CraftServer) Bukkit.getServer()).getServer(), netManager, this));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ this.setSneaking(this.detect.isSneaking());
+ this.setSprinting(this.detect.isSprinting());
+ this.getBukkitEntity().setCanPickupItems(this.detect.getCanPickupItems());
+ final Location l = this.detect.getLocation();
+ l.setX(l.getX() + x);
+ l.setZ(l.getZ() + z);
+ for (int i = 0; i < 500; ++i) {
+ if (l.getBlock().getRelative(BlockFace.DOWN, i).getType() != Material.AIR && l.getBlock().getRelative(BlockFace.DOWN, i).getType().isSolid()) {
+ l.setY(l.getY() - (i - 1));
+ i = 500;
}
- }, 20L);
+ }
+ for (int i = 0; i < 500; ++i) {
+ if (l.getBlock().getRelative(BlockFace.UP, i).getType() != Material.AIR && l.getBlock().getRelative(BlockFace.UP, i).getType().isSolid()) {
+ l.setY(l.getY() + (i + 1));
+ }
+ if (l.getBlock().getRelative(BlockFace.UP, i + 1).getType() == Material.AIR) {
+ i = 500;
+ }
+ }
+ this.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
+ if (!l.getBlock().getRelative(BlockFace.UP, 0).getType().isSolid() && !l.getBlock().getRelative(BlockFace.UP, 1).getType().isSolid()) {
+ this.enderTeleportTo(l.getX(), l.getY(), l.getZ());
+ }
+ this.packet = new PacketPlayOutNamedEntitySpawn(this);
+ this.runPlayerUpdate();
+ p.sendPacket(this.packet);
+ this.fauxSleeping = true;
+ this.player = this;
+
+ new BukkitRunnable() {
+
+ @Override
+ public void run() {
+ for(NPC npc : npcs) {
+ PacketPlayOutEntityHeadRotation headRotationPacket = new PacketPlayOutEntityHeadRotation(npc.getBukkitEntity().getHandle(), getCompressedAngle(detect.getEyeLocation().getYaw()));
+ PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(npc.getBukkitEntity().getHandle());
+ PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true);
+ for(CustomPlayer player : Core.getOnlinePlayers()) {
+ player.sendPacket(headRotationPacket);
+ player.sendPacket(teleportPacket);
+ player.sendPacket(metadataPacket);
+ }
+ }
+ }
+ }.runTaskTimerAsynchronously(Core.getInstance(), 0L, 0L);
}
- public void spawn() {
- PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
-
- setField(packet, "a", entityID);
- setField(packet, "b", gameProfile.getId());
- setField(packet, "c", location.getX());
- setField(packet, "d", location.getY());
- setField(packet, "e", location.getZ());
- setField(packet, "f", location.getYaw());
- setField(packet, "g", location.getPitch());
- setField(packet, "h", dataWatcher);
-
- for(CustomPlayer player : Core.getOnlinePlayers()) player.sendPacket(packet);
- }
-
- public void setSkin(String value, String signature) {
- gameProfile.getProperties().put("textures", new Property("textures", value, signature));
+ private byte getCompressedAngle(float value) {
+ return (byte) (value * 256.0F / 360F);
}
public void remove() {
- PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(entityID);
- for(CustomPlayer player : Core.getOnlinePlayers()) player.sendPacket(packet);
- }
-
- private void addToTablist() {
-
- }
-
- private void removeFromTablist() {
-
- }
-
- private void setField(Object instance, String field, Object value) {
- try {
- Field f = instance.getClass().getDeclaredField(field);
- f.setAccessible(true);
- f.set(instance, value);
- } catch (NoSuchFieldException | IllegalAccessException e) {
- e.printStackTrace();
+ if (npcs.contains(this)) {
+ npcs.remove(this);
+ }
+ this.task.cancel();
+ for (CustomPlayer players : Core.getOnlinePlayers()) {
+ final PacketPlayOutEntityDestroy teleport = new PacketPlayOutEntityDestroy(player.getId());
+ players.sendPacket(teleport);
}
}
-
- /*
- int entityID;
- Location location;
- GameProfile gameprofile;
-
-
- public NPC(String name,Location location){
- entityID = (int)Math.ceil(Math.random() * 1000) + 2000;
- gameprofile = new GameProfile(UUID.randomUUID(), name);
- this.location = location;
+ public void setMessage(final String message) {
+ this.message = message;
}
- public void spawn(){
- PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
+ public void runPlayerUpdate() {
+ this.task = new BukkitRunnable() {
+ public void run() {
+ if (detect != null) {
+ if (Bukkit.getPlayerExact(detect.getName()) != null) {
+ if (!getBukkitEntity().isDead()) {
+ setSneaking(detect.isSneaking());
+ setSprinting(detect.isSprinting());
+ EnumItemSlot[] values;
+ for (int length = (values = EnumItemSlot.values()).length, j = 0; j < length; ++j) {
+ final EnumItemSlot slot = values[j];
+ final PacketPlayOutEntityEquipment equip = new PacketPlayOutEntityEquipment(getBukkitEntity().getEntityId(), slot, getEquip(slot));
+ for (CustomPlayer players : Core.getOnlinePlayers()) {
+ players.sendPacket(equip);
+ }
+ }
+ final Location l = detect.getLocation();
+ l.setX(l.getX() + x);
+ l.setZ(l.getZ() + z);
+ for (int i = 0; i < 500; ++i) {
+ if (l.getBlock().getRelative(BlockFace.DOWN, i).getType() != Material.AIR && l.getBlock().getRelative(BlockFace.DOWN, i).getType().isSolid()) {
+ l.setY(l.getY() - (i - 1));
+ i = 500;
+ }
+ }
+ for (int i = 0; i < 500; ++i) {
+ if (l.getBlock().getRelative(BlockFace.UP, i).getType() != Material.AIR && l.getBlock().getRelative(BlockFace.UP, i).getType().isSolid()) {
+ l.setY(l.getY() + (i + 1));
+ }
+ if (l.getBlock().getRelative(BlockFace.UP, i + 1).getType() == Material.AIR) {
+ i = 500;
+ }
+ }
+ if (!l.getBlock().getRelative(BlockFace.UP, 0).getType().isSolid() && !l.getBlock().getRelative(BlockFace.UP, 1).getType().isSolid()) {
+ enderTeleportTo(l.getX(), l.getY(), l.getZ());
+ }
+ NPC.access$0(NPC.this, l.getYaw(), l.getPitch());
+ aK = l.getYaw();
+ aL = l.getYaw();
+ getBukkitEntity().setCanPickupItems(detect.getCanPickupItems());
+ } else {
+ this.cancel();
+ }
+ } else {
+ this.cancel();
+ }
+ } else {
+ this.cancel();
+ }
+ }
- setValue(packet, "a", entityID);
- setValue(packet, "b", gameprofile.getId());
- setValue(packet, "c", (int)MathHelper.floor(location.getX() * 32.0D));
- setValue(packet, "d", (int)MathHelper.floor(location.getY() * 32.0D));
- setValue(packet, "e", (int)MathHelper.floor(location.getZ() * 32.0D));
- setValue(packet, "f", (byte) ((int) (location.getYaw() * 256.0F / 360.0F)));
- setValue(packet, "g", (byte) ((int) (location.getPitch() * 256.0F / 360.0F)));
- setValue(packet, "h", 0);
- DataWatcher w = new DataWatcher(null);
- w.a(6,(float)20);
- w.a(10,(byte)127);
- setValue(packet, "i", w);
- addToTablist();
- sendPacket(packet);
+ private ItemStack getEquip(final EnumItemSlot slot) {
+ switch (slot) {
+ case MAINHAND: return CraftItemStack.asNMSCopy(detect.getInventory().getItemInMainHand());
+ case OFFHAND: return CraftItemStack.asNMSCopy(detect.getInventory().getItemInOffHand());
+ case FEET: return CraftItemStack.asNMSCopy(detect.getInventory().getBoots());
+ case LEGS: return CraftItemStack.asNMSCopy(detect.getInventory().getLeggings());
+ case CHEST: return CraftItemStack.asNMSCopy(detect.getInventory().getChestplate());
+ case HEAD: return CraftItemStack.asNMSCopy(detect.getInventory().getHelmet());
+ default: return null;
+ }
+ }
+ }.runTaskTimer(Core.getInstance(), 0L, 0L);
}
- public void destroy(){
- PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] {entityID});
- rmvFromTablist();
- sendPacket(packet);
+ public boolean damageEntity(final DamageSource damagesource, final float f) {
+ if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.ARROW) {
+ final Arrow a = (Arrow) damagesource.getEntity().getBukkitEntity();
+ if (a.getShooter() != null) {
+ if (a.getShooter() instanceof Player) {
+ final Player shooter = (Player) a.getShooter();
+ if (this.detect != null && !shooter.getName().equals(this.detect.getName())) {
+ this.playEffect();
+ this.remove();
+ shooter.sendMessage(this.message);
+ if (npcs.contains(this)) {
+ npcs.remove(this);
+ }
+ }
+ }
+ } else {
+ this.remove();
+ }
+ }
+ if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.SNOWBALL) {
+ final Snowball a2 = (Snowball) damagesource.getEntity().getBukkitEntity();
+ if (a2.getShooter() != null) {
+ if (a2.getShooter() instanceof Player) {
+ final Player shooter = (Player) a2.getShooter();
+ if (this.detect != null && !shooter.getName().equals(this.detect.getName())) {
+ this.playEffect();
+ this.remove();
+ shooter.sendMessage(this.message);
+ if (npcs.contains(this)) {
+ npcs.remove(this);
+ }
+ }
+ }
+ } else {
+ this.remove();
+ }
+ }
+ if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.EGG) {
+ final Egg a3 = (Egg) damagesource.getEntity().getBukkitEntity();
+ if (a3.getShooter() != null) {
+ if (a3.getShooter() instanceof Player) {
+ final Player shooter = (Player) a3.getShooter();
+ if (this.detect != null && !shooter.getName().equals(this.detect.getName())) {
+ this.playEffect();
+ this.remove();
+ shooter.sendMessage(this.message);
+ if (npcs.contains(this)) {
+ npcs.remove(this);
+ }
+ }
+ }
+ } else {
+ this.remove();
+ }
+ }
+ if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.FIREBALL) {
+ final Fireball a4 = (Fireball) damagesource.getEntity().getBukkitEntity();
+ if (a4.getShooter() != null) {
+ if (a4.getShooter() instanceof Player) {
+ final Player shooter = (Player) a4.getShooter();
+ if (this.detect != null && !shooter.getName().equals(this.detect.getName())) {
+ this.playEffect();
+ this.remove();
+ shooter.sendMessage(this.message);
+ if (npcs.contains(this)) {
+ npcs.remove(this);
+ }
+ }
+ }
+ } else {
+ this.remove();
+ }
+ }
+ if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.PLAYER && this.detect != null && !damagesource.getEntity().getName().equals(this.detect.getName())) {
+ this.playEffect();
+ this.remove();
+ final Player damager = (Player) damagesource.getEntity().getBukkitEntity();
+ damager.sendMessage(this.message);
+ if (npcs.contains(this)) {
+ npcs.remove(this);
+ }
+ }
+ return false;
}
- public void addToTablist(){
- PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
- PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameprofile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameprofile.getName())[0]);
- @SuppressWarnings("unchecked")
- List players = (List) getValue(packet, "b");
- players.add(data);
-
- setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
- setValue(packet, "b", players);
-
- sendPacket(packet);
+ public void playEffect() {
+ this.remove();
+ for (final Player all : Bukkit.getOnlinePlayers()) {
+ final Location l = this.getBukkitEntity().getLocation();
+ float i = 0.3f;
+ for (int a = 0; a <= 5; ++a) {
+ i = i + 0.3f;
+ final PacketPlayOutWorldParticles particle = new PacketPlayOutWorldParticles(EnumParticle.CLOUD, true, (float) l.getX(), (float) l.getY() + i, (float) l.getZ(), 0.0f, 0.0f, 0.0f, 0.0f, 10);
+ ((CraftPlayer) all).getHandle().playerConnection.sendPacket(particle);
+ }
+ }
}
- public void rmvFromTablist(){
- PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
- PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameprofile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameprofile.getName())[0]);
- @SuppressWarnings("unchecked")
- List players = (List) getValue(packet, "b");
- players.add(data);
-
- setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
- setValue(packet, "b", players);
-
- sendPacket(packet);
+ public Player getPlayer() {
+ return this.detect;
+ }
+
+ static /* synthetic */ void access$0(final NPC npc, final float n, final float n2) {
+ npc.setYawPitch(n, n2);
}
- */
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/npc/NPCChannel.java b/src/main/java/eu/univento/core/api/npc/NPCChannel.java
new file mode 100644
index 0000000..448cc66
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/npc/NPCChannel.java
@@ -0,0 +1,67 @@
+package eu.univento.core.api.npc;
+
+import io.netty.channel.*;
+
+import java.net.SocketAddress;
+
+/**
+ * @author Ploxh4D
+ * @version 1.0
+ */
+
+public class NPCChannel extends AbstractChannel {
+ private final ChannelConfig config;
+
+ protected NPCChannel(final Channel parent) {
+ super(parent);
+ this.config = new DefaultChannelConfig(this);
+ }
+
+ public ChannelConfig config() {
+ this.config.setAutoRead(true);
+ return this.config;
+ }
+
+ public boolean isActive() {
+ return false;
+ }
+
+ public boolean isOpen() {
+ return false;
+ }
+
+ public ChannelMetadata metadata() {
+ return null;
+ }
+
+ protected void doBeginRead() throws Exception {
+ }
+
+ protected void doBind(final SocketAddress arg0) throws Exception {
+ }
+
+ protected void doClose() throws Exception {
+ }
+
+ protected void doDisconnect() throws Exception {
+ }
+
+ protected void doWrite(final ChannelOutboundBuffer arg0) throws Exception {
+ }
+
+ protected boolean isCompatible(final EventLoop arg0) {
+ return true;
+ }
+
+ protected SocketAddress localAddress0() {
+ return null;
+ }
+
+ protected AbstractChannel.AbstractUnsafe newUnsafe() {
+ return null;
+ }
+
+ protected SocketAddress remoteAddress0() {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/npc/NPCNetworkManager.java b/src/main/java/eu/univento/core/api/npc/NPCNetworkManager.java
new file mode 100644
index 0000000..fd0c933
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/npc/NPCNetworkManager.java
@@ -0,0 +1,15 @@
+package eu.univento.core.api.npc;
+
+import net.minecraft.server.v1_11_R1.EnumProtocolDirection;
+import net.minecraft.server.v1_11_R1.NetworkManager;
+
+/**
+ * @author Ploxh4D
+ * @version 1.0
+ */
+public class NPCNetworkManager extends NetworkManager{
+
+ public NPCNetworkManager(EnumProtocolDirection enumprotocoldirection) {
+ super(enumprotocoldirection);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/npc/NPCPlayerConnection.java b/src/main/java/eu/univento/core/api/npc/NPCPlayerConnection.java
new file mode 100644
index 0000000..8b64387
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/npc/NPCPlayerConnection.java
@@ -0,0 +1,17 @@
+package eu.univento.core.api.npc;
+
+import net.minecraft.server.v1_11_R1.EntityPlayer;
+import net.minecraft.server.v1_11_R1.MinecraftServer;
+import net.minecraft.server.v1_11_R1.NetworkManager;
+import net.minecraft.server.v1_11_R1.PlayerConnection;
+
+/**
+ * @author joethei
+ * @version 0.1
+ */
+public class NPCPlayerConnection extends PlayerConnection{
+
+ public NPCPlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
+ super(minecraftserver, networkmanager, entityplayer);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java b/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java
deleted file mode 100644
index aa2ad3d..0000000
--- a/src/main/java/eu/univento/core/api/npc/datawatcher/EnumDataWatcher.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package eu.univento.core.api.npc.datawatcher;
-
-import lombok.Getter;
-
-/**
- * @author ingrim4, joethei
- * @version 1.0
- */
-enum EnumDataWatcher {
-
- //TODO: fix field
-
- ENTITY_BITMASK_00("Entity", "ay"),//
- ENTITY_AIR_01("Entity", "az"),//AIR
- ENTITY_NAME_02("Entity", "aA"),//CUSTOM_NAME
- ENTITY_NAME_VISIBLE_03("Entity", "aB"),//CUSTOM_NAME_VISIBLE
- ENTITY_SILENT_04("Entity", "aC"),//SILENT
-
- LIVING_HAND_05("EntityLiving", "as"),
- LIVING_HEALTH_06("EntityLiving", "HEALTH"),
- LIVING_POTION_COLOR_07("EntityLiving", "f"),
- LIVING_POTION_AMBIENT_08("EntityLiving", "g"),
- LIVING_ARROWS_09("EntityLiving", "h"),
-
- HUMAN_ABSORTION_10("EntityHuman", ""),
- HUMAN_SCORE_11("EntityHuman", ""),
- HUMAN_SKIN_12("EntityHuman", ""),
- HUMAN_HAND_13("EntityHuman", "");
-
- @Getter
- private String owner;
- @Getter
- private String field;
-
- EnumDataWatcher(String owner, String field) {
- this.owner = owner;
- this.field = field;
- }
-
- public Object getObject() {
- return null;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/npc/datawatcher/NullDataWatcher.java b/src/main/java/eu/univento/core/api/npc/datawatcher/NullDataWatcher.java
deleted file mode 100644
index 9b7210f..0000000
--- a/src/main/java/eu/univento/core/api/npc/datawatcher/NullDataWatcher.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package eu.univento.core.api.npc.datawatcher;
-
-import eu.univento.core.api.utils.reflection.IReflection;
-
-/**
- * @author ingrim4, joethei
- * @version 1.0
- */
-public class NullDataWatcher {
-
- private static final Class> CLASS_DATAWATCHER = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "DataWatcher");
- private static final IReflection.ConstructorAccessor CONSTRUCTOR_DATAWATCHER_ENTITY = IReflection.getConstructor(CLASS_DATAWATCHER, IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "Entity"));
-
- private static final Class> CLASS_DATAWATCHER_OBJECT = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "DataWatcherObject");
-
- private static final Class> CLASS_DATAWATCHER_ITEM = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "DataWatcher$Item");
- private static final IReflection.MethodAccessor METHOD_DATAWATCHER_ITEM_SETDATA = IReflection.getMethod(CLASS_DATAWATCHER_ITEM, "a", Object.class);
-
- private static final IReflection.MethodAccessor METHOD_DATAWATCHER_REGISTER = IReflection.getMethod(CLASS_DATAWATCHER, "register", CLASS_DATAWATCHER_OBJECT, Object.class);
- private static final IReflection.MethodAccessor METHOD_DATAWATCHER_GETITEM = IReflection.getMethod(CLASS_DATAWATCHER, "c", CLASS_DATAWATCHER_OBJECT, Object.class);
-
- private static final IReflection.MethodAccessor METHOD_DATAWATCHER_C = IReflection.getMethod(CLASS_DATAWATCHER, "c");
-
- private final Object dataWatcher;
-
- public NullDataWatcher() {
- this.dataWatcher = CONSTRUCTOR_DATAWATCHER_ENTITY.newInstance(new Object[]{null});
-
- }
-
- public NullDataWatcher add(EnumDataWatcher dataWatcher, Object value) {
- METHOD_DATAWATCHER_REGISTER.invoke(this.dataWatcher, dataWatcher.getObject(), value);
- return this;
- }
-
- public NullDataWatcher update(EnumDataWatcher dataWatcher, Object value) {
- Object item = METHOD_DATAWATCHER_GETITEM.invoke(this.dataWatcher, dataWatcher.getObject());
- METHOD_DATAWATCHER_ITEM_SETDATA.invoke(item, value);
- return this;
- }
-
- public Object toPacket() {
- return METHOD_DATAWATCHER_C.invoke(this.dataWatcher);
- }
-
- public Object toNMS() {
- return this.dataWatcher;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/player/CustomPlayer.java b/src/main/java/eu/univento/core/api/player/CustomPlayer.java
index e1ff5c2..ae8b784 100644
--- a/src/main/java/eu/univento/core/api/player/CustomPlayer.java
+++ b/src/main/java/eu/univento/core/api/player/CustomPlayer.java
@@ -14,7 +14,6 @@ import eu.univento.core.api.gui.hologram.HologramData;
import eu.univento.core.api.server.ServerSettings;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import io.vertx.core.json.JsonObject;
import lombok.Getter;
import net.minecraft.server.v1_11_R1.*;
import org.bukkit.*;
@@ -60,8 +59,7 @@ public class CustomPlayer extends CraftPlayer {
private final GameProfile gameProfile;
- @Getter
- private HologramData hologramData;
+ @Getter private HologramData hologramData;
private CustomPlayer(Player player) {
super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle());
@@ -79,15 +77,16 @@ public class CustomPlayer extends CraftPlayer {
location.put("X", getLocation().getX());
location.put("Y", getLocation().getY());
location.put("Z", getLocation().getZ());
- location.put("Yaw", getLocation().getYaw());
- location.put("Pitch", getLocation().getPitch());
+ location.put("Yaw", String.valueOf(getLocation().getYaw()));
+ location.put("Pitch", String.valueOf(getLocation().getPitch()));
- if (ServerSettings.isLobby()) DATABASE_PLAYER.setInDatabase("Pos", new JsonObject(location));
+ if (ServerSettings.isLobby()) DATABASE_PLAYER.setInDatabase("Pos", location);
if (PLAYERS.containsKey(getUniqueId())) PLAYERS.remove(getUniqueId());
}
public static CustomPlayer getPlayer(String player) {
+ if(Bukkit.getPlayer(player) == null) return null;
Player p = Bukkit.getPlayer(player);
if (PLAYERS.containsKey(p.getUniqueId())) {
return PLAYERS.get(p.getUniqueId());
@@ -120,11 +119,9 @@ public class CustomPlayer extends CraftPlayer {
public CompletableFuture getLastLocation() {
CompletableFuture future = new CompletableFuture<>();
- DATABASE_PLAYER.getObjectFromDatabase("POS").whenComplete((entries, throwable) -> {
- future.complete(new Location(Bukkit.getWorld("world"), entries.getDouble("X"), entries.getDouble("Y"),
- entries.getDouble("Z"), entries.getFloat("Yaw"), entries.getFloat("Pitch")));
- });
-
+ DATABASE_PLAYER.getObjectFromDatabase("POS").whenComplete((entries, throwable) ->
+ future.complete(new Location(Bukkit.getWorld("world"), entries.getDouble("X"), entries.getDouble("Y"), entries.getDouble("Z"),
+ Float.parseFloat(entries.getString("Yaw")), Float.parseFloat(entries.getString("Pitch")))));
return future;
}
@@ -416,7 +413,7 @@ public class CustomPlayer extends CraftPlayer {
ByteBuf byteBuf = Unpooled.copiedBuffer(byteOut.toByteArray());
PacketDataSerializer packetDataSerializer = new PacketDataSerializer(byteBuf);
PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload("LABYMOD", packetDataSerializer);
- getHandle().playerConnection.sendPacket(packet);
+ sendPacket(packet);
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/java/eu/univento/core/api/player/Skin.java b/src/main/java/eu/univento/core/api/player/Skin.java
index eaae34b..dd4a356 100644
--- a/src/main/java/eu/univento/core/api/player/Skin.java
+++ b/src/main/java/eu/univento/core/api/player/Skin.java
@@ -1,15 +1,17 @@
package eu.univento.core.api.player;
+import lombok.Getter;
+import org.bukkit.Bukkit;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
import java.util.logging.Level;
-import org.bukkit.Bukkit;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-
+@Getter
class Skin {
private final String uuid;
private String name;
@@ -17,9 +19,6 @@ class Skin {
private String signature;
Skin(String uuid){this.uuid = uuid;load();}
- String getSkinValue(){return value;}
- String getSkinName(){return name;}
- String getSkinSignature(){return signature;}
private void load(){
try {
diff --git a/src/main/java/eu/univento/core/api/server/GameInfo.java b/src/main/java/eu/univento/core/api/server/GameInfo.java
index 115037c..d097eee 100644
--- a/src/main/java/eu/univento/core/api/server/GameInfo.java
+++ b/src/main/java/eu/univento/core/api/server/GameInfo.java
@@ -1,5 +1,6 @@
package eu.univento.core.api.server;
+import eu.univento.commons.server.ServerInfo;
import eu.univento.commons.server.ServerType;
/**
diff --git a/src/main/java/eu/univento/core/api/server/NetworkData.java b/src/main/java/eu/univento/core/api/server/NetworkData.java
index e9e926f..baf5518 100644
--- a/src/main/java/eu/univento/core/api/server/NetworkData.java
+++ b/src/main/java/eu/univento/core/api/server/NetworkData.java
@@ -3,6 +3,7 @@ package eu.univento.core.api.server;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
+import eu.univento.commons.server.ServerType;
import eu.univento.core.Core;
import eu.univento.core.api.player.CustomPlayer;
import org.bukkit.entity.Player;
@@ -36,7 +37,7 @@ public class NetworkData implements PluginMessageListener{
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if(!channel.equals("BungeeCord")) return;
- Core.getCommons().getLoggingHandler().getCore().info("Daten incomming");
+ Core.getCommons().getLoggingHandler().log(ServerType.getServerType(), "Daten incomming");
ByteArrayDataInput input = ByteStreams.newDataInput(message);
String subchannel = input.readUTF();
diff --git a/src/main/java/eu/univento/core/api/server/ServerInfo.java b/src/main/java/eu/univento/core/api/server/ServerInfo.java
deleted file mode 100644
index 0fc95c0..0000000
--- a/src/main/java/eu/univento/core/api/server/ServerInfo.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package eu.univento.core.api.server;
-
-import eu.univento.commons.server.ServerType;
-
-import java.util.regex.Pattern;
-
-/**
- * @author joethei
- * @version 1.0
- */
-public class ServerInfo {
-
- private final String name;
- private final ServerPinger pinger;
-
- public ServerInfo(String name) {
- this.name = name;
- pinger = new ServerPinger(name);
- pinger.ping();
- }
-
- public String getName() {
- return name;
- }
-
- public ServerType getGame() {
- String[] parts = getMotd().split(Pattern.quote(";"));
- return ServerType.valueOf(parts[0]);
- }
-
- public String getGameState() {
- String[] parts = getMotd().split(Pattern.quote(";"));
- return parts[1];
- }
-
- public boolean isOnline() {
- return pinger.isOnline();
- }
-
- public int getOnlinePlayers() {
- return pinger.getPlayerCount();
- }
-
- public int getMaxPlayers() {
- return pinger.getMaxPlayers();
- }
-
- public String getMotd() {
- //return ServerDatabase.getMotd(name);
- return null;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/server/ServerSettings.java b/src/main/java/eu/univento/core/api/server/ServerSettings.java
index 8e8c28c..dac49b2 100644
--- a/src/main/java/eu/univento/core/api/server/ServerSettings.java
+++ b/src/main/java/eu/univento/core/api/server/ServerSettings.java
@@ -1,96 +1,28 @@
package eu.univento.core.api.server;
import eu.univento.commons.server.ServerType;
-import eu.univento.core.Core;
-import eu.univento.core.commands.Build;
-import eu.univento.core.listeners.Blocks;
-import org.bukkit.Bukkit;
+import lombok.Getter;
+import lombok.Setter;
import org.bukkit.GameMode;
-import org.bukkit.plugin.PluginManager;
/**
* @author joethei
- * @version 0.1
+ * @version 1.0
*/
+
public class ServerSettings {
- private static boolean build;
- private static boolean lobby;
- private static boolean debug;
- private static boolean mute;
- private static boolean game;
- private static ServerType serverType;
- private static GameMode gameMode;
- private static String gameState;
-
- public static ServerType getServerType() {
- return serverType;
- }
+ @Getter @Setter private static boolean lobby;
+ @Getter @Setter private static boolean debug;
+ @Getter @Setter private static boolean mute;
+ @Getter @Setter private static boolean game;
+ @Getter private static ServerType serverType;
+ @Getter @Setter private static GameMode gameMode;
+ @Getter @Setter private static String gameState;
+ @Getter @Setter private static int maxPlayers;
public static void setServerType(ServerType serverType) {
ServerSettings.serverType = serverType;
- }
-
- public static GameMode getGameMode() {
- return gameMode;
- }
-
- public static void setGameMode(GameMode gameMode) {
- ServerSettings.gameMode = gameMode;
- }
-
- public static boolean isGame() {
- return game;
- }
-
- public static void setGame(boolean game) {
- ServerSettings.game = game;
- }
-
- public static boolean isBuild() {
- return build;
- }
-
- public static void setBuild(boolean build) {
- ServerSettings.build = build;
- Core.getCommons().getLoggingHandler().getCore().info("Build ist " + build);
- if(build) {
- PluginManager pm = Bukkit.getPluginManager();
- new Build(Core.getInstance(), "build", "Bau Modus an/ausschalten", "b");
- pm.registerEvents(new Blocks(), Core.getInstance());
- Core.getCommons().getLoggingHandler().getCore().info("Build Modus aktiviert");
- }
- }
-
- public static boolean isLobby() {
- return lobby;
- }
-
- public static void setLobby() {
- ServerSettings.lobby = true;
- }
-
- public static boolean isDebug() {
- return debug;
- }
-
- public static void setDebug() {
- ServerSettings.debug = true;
- }
-
- public static boolean isMute() {
- return mute;
- }
-
- public static void setMute(boolean mute) {
- ServerSettings.mute = mute;
- }
-
- public static String getGameState() {
- return gameState;
- }
-
- public static void setGameState(String gameState) {
- ServerSettings.gameState = gameState;
+ ServerType.setServerType(serverType);
}
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/update/PluginUpdater.java b/src/main/java/eu/univento/core/api/update/PluginUpdater.java
index efe195a..1c39a58 100644
--- a/src/main/java/eu/univento/core/api/update/PluginUpdater.java
+++ b/src/main/java/eu/univento/core/api/update/PluginUpdater.java
@@ -6,6 +6,7 @@
package eu.univento.core.api.update;
import eu.univento.core.Core;
+import eu.univento.core.api.server.ServerSettings;
import org.apache.commons.io.FileUtils;
import org.gitlab.api.GitlabAPI;
import org.gitlab.api.TokenType;
@@ -47,7 +48,7 @@ public class PluginUpdater {
FileUtils.deleteQuietly(zip);
FileUtils.deleteDirectory(output);
} catch (IOException e) {
- Core.getCommons().getLoggingHandler().getCore().error("Failed while trying to update plugin: " + name);
+ Core.getCommons().getLoggingHandler().log(ServerSettings.getServerType(), "Failed while trying to update plugin: " + name);
e.printStackTrace();
}
}
diff --git a/src/main/java/eu/univento/core/api/world/WorldReset.java b/src/main/java/eu/univento/core/api/world/WorldReset.java
index 05d33cc..2f9da05 100644
--- a/src/main/java/eu/univento/core/api/world/WorldReset.java
+++ b/src/main/java/eu/univento/core/api/world/WorldReset.java
@@ -5,19 +5,7 @@
package eu.univento.core.api.world;
-import org.apache.commons.io.FileUtils;
-import org.apache.http.HttpEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.bukkit.Bukkit;
import org.bukkit.World;
-import org.bukkit.WorldCreator;
-import org.bukkit.entity.Player;
-
-import java.io.File;
-import java.io.IOException;
/**
* @author joethei
@@ -31,43 +19,9 @@ public class WorldReset {
this.name = name;
}
+ //TODO: add functionality
public World reset() {
- World world = Bukkit.getWorld(name);
- if(world.getName().equals("world")) return null;
- for(Player player : world.getPlayers())
- player.teleport(Bukkit.getWorld("world").getSpawnLocation());
-
- Bukkit.unloadWorld(world, true);
- try {
- File file = new File(name);
- FileUtils.deleteDirectory(file);
-
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- HttpGet httpGet = new HttpGet("https://download.univento.eu/world" + name);
- httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0");
- httpGet.addHeader("Referer", "https://www.google.com");
-
- try {
- CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
- HttpEntity fileEntity = httpResponse.getEntity();
-
- if (fileEntity != null) {
- FileUtils.copyInputStreamToFile(fileEntity.getContent(), new File(name));
- }
-
- } catch (IOException e) {
- return null;
- }
-
- httpGet.releaseConnection();
-
- //FileUtils.copyURLToFile(new URL(""), file);
-
- } catch (IOException e) {
- e.printStackTrace();
- }
- return Bukkit.createWorld(new WorldCreator(name));
+ return null;
}
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/Build.java b/src/main/java/eu/univento/core/commands/Build.java
deleted file mode 100644
index cef1b6a..0000000
--- a/src/main/java/eu/univento/core/commands/Build.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.server.ServerSettings;
-import org.bukkit.GameMode;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-
-import java.util.HashMap;
-import java.util.List;
-
-/**
- * lets player build
- * @author joethei
- * @version 1.0
- */
-public class Build extends AutoCommand{
-
- /**
- * player who can build
- */
- private static final HashMap players = new HashMap<>();
-
- /**
- * @return player that can build
- */
- public static HashMap getPlayers() {
- return players;
- }
-
- /**
- * @param plugin main class
- * @param command command
- * @param description describes the commons
- * @param aliases aliases of commons
- */
- public Build(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
- //Messages msgs = new Messages(p);
- if(p.getDatabasePlayer().isAllowed(Rank.Builder)) {
- if(players.containsKey(p)) {
- //p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_OFF());
-
- ItemStack[] content = players.get(p);
- p.getInventory().setContents(content);
- players.remove(p);
- p.setGameMode(ServerSettings.getGameMode());
- }else {
- players.put(p, p.getInventory().getContents());
- //p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_ON());
- p.getInventory().clear();
- p.setGameMode(GameMode.CREATIVE);
- }
- }else {
- //sender.sendMessage(msgs.NO_PERMS());
- }
- }else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return false;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return null;
- }
-
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/BuilderCommands.java b/src/main/java/eu/univento/core/commands/BuilderCommands.java
new file mode 100644
index 0000000..73f61a9
--- /dev/null
+++ b/src/main/java/eu/univento/core/commands/BuilderCommands.java
@@ -0,0 +1,74 @@
+package eu.univento.core.commands;
+
+import eu.univento.commons.player.rank.Rank;
+import eu.univento.core.api.command.Command;
+import eu.univento.core.api.command.CommandArgs;
+import eu.univento.core.api.command.Completer;
+import eu.univento.core.api.player.CustomPlayer;
+import eu.univento.core.api.server.ServerSettings;
+import lombok.Getter;
+import org.bukkit.GameMode;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author joethei
+ * @version 1.0
+ */
+public class BuilderCommands {
+
+ @Getter private static HashMap buildPlayers = new HashMap<>();
+
+ @Command(name = "build", description = "set yourself into build mode", rank = Rank.JrBuilder, inGameOnly = true)
+ public void build(CommandArgs args) {
+ if(buildPlayers.containsKey(args.getPlayer())) {
+ args.getPlayer().getInventory().setContents(buildPlayers.get(args.getPlayer()));
+ buildPlayers.remove(args.getPlayer());
+ args.getPlayer().setGameMode(ServerSettings.getGameMode());
+ }else {
+ buildPlayers.put(args.getPlayer(), args.getPlayer().getInventory().getContents());
+ args.getPlayer().getInventory().clear();
+ args.getPlayer().setGameMode(GameMode.CREATIVE);
+ }
+ }
+
+ @Command(name = "gamemode", aliases = {"gm"}, description = "change your gamemode", rank = Rank.Builder, inGameOnly = true)
+ public void gamemode(CommandArgs args) {
+ if(args.length() == 1) {
+ args.getPlayer().setGameMode(getModeFromString(args.getArg(0)));
+ }
+ }
+
+ @Completer(name = "gamemode", aliases = {"gm"})
+ public List gameModeCompletor(CommandArgs args) {
+ List list = new ArrayList<>();
+
+ list.add("0");
+ list.add("1");
+ list.add("2");
+ list.add("3");
+ list.add("Survival");
+ list.add("Creative");
+ list.add("Adventure");
+ list.add("Spectator");
+
+ return list;
+ }
+
+ private GameMode getModeFromString(String string) {
+ switch(string) {
+ case "0" : return GameMode.SURVIVAL;
+ case "1" : return GameMode.CREATIVE;
+ case "2": return GameMode.ADVENTURE;
+ case "3" : return GameMode.SPECTATOR;
+ case "Survial" : return GameMode.SURVIVAL;
+ case "Creative" : return GameMode.CREATIVE;
+ case "Adventure" : return GameMode.ADVENTURE;
+ case "Spectator" : return GameMode.SPECTATOR;
+ default: return GameMode.SPECTATOR;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/ChatClear.java b/src/main/java/eu/univento/core/commands/ChatClear.java
deleted file mode 100644
index fdae9b3..0000000
--- a/src/main/java/eu/univento/core/commands/ChatClear.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.List;
-
-/**
- * @author joethei
- * @version 1.0
- */
-public class ChatClear extends AutoCommand {
-
- public ChatClear(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
- if(p.getDatabasePlayer().isAllowed(Rank.Supporter)) {
- for(int i = 0; i <= 100; i++) {
- Bukkit.broadcastMessage(" ");
- }
- for(Player players : Bukkit.getOnlinePlayers()) {
- CustomPlayer player = CustomPlayer.getPlayer(players);
- if (player.getDatabasePlayer().isAllowed(Rank.Supporter)) {
- //Messages messages = new Messages(player);
- //player.sendMessage(messages.Core_CHAT_CLEARED(p));
- }
- }
- }else {
- //p.sendMessage(msgs.NO_PERMS());
- }
- }else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return true;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return null;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/DevCommands.java b/src/main/java/eu/univento/core/commands/DevCommands.java
new file mode 100644
index 0000000..5b9cc22
--- /dev/null
+++ b/src/main/java/eu/univento/core/commands/DevCommands.java
@@ -0,0 +1,100 @@
+package eu.univento.core.commands;
+
+import eu.univento.commons.player.rank.Rank;
+import eu.univento.core.Core;
+import eu.univento.core.api.command.Command;
+import eu.univento.core.api.command.CommandArgs;
+import eu.univento.core.api.command.Completer;
+import eu.univento.core.api.player.CustomPlayer;
+import eu.univento.core.api.server.ServerSettings;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
+import org.bukkit.entity.ArmorStand;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author joethei
+ * @version 1.0
+ */
+public class DevCommands {
+
+ private ArrayList trolledPlayers = new ArrayList<>();
+
+ @Command(name = "runas", description = "run commands as other players", usage = "runas", rank = Rank.SrDeveloper, inGameOnly = true)
+ public void runAs(CommandArgs args) {
+ if (args.length() >= 2) {
+ CustomPlayer t = CustomPlayer.getPlayer(args.getArg(0));
+ if (t != null) {
+ StringBuilder msg = new StringBuilder();
+ for (int i = 1; i < args.length(); i++) {
+ msg.append(args.getArg(i)).append(" ");
+ }
+ t.chat(msg.toString());
+ }
+ }
+ }
+
+ @Completer(name = "runas")
+ public List runAsCompleter(CommandArgs args) {
+ return Core.getOnlinePlayers().stream().map(CustomPlayer::getDisplayName).collect(Collectors.toList());
+ }
+
+
+ @Command(name = "systeminfo", description = "some infos about the system", usage = "/systeminfo", rank = Rank.JrDeveloper, inGameOnly = true)
+ public void systemInfo(CommandArgs args) {
+ CustomPlayer p = args.getPlayer();
+ Runtime run = Runtime.getRuntime();
+ p.sendMessage("§6§l===SystemInfo <" + Bukkit.getServerName() + ">===");
+ try {
+ p.sendMessage("§6Server: " + InetAddress.getLocalHost().getHostName());
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+ p.sendMessage("§6TPS: " + Bukkit.getTPS()[0]);
+ p.sendMessage("§6Spigot version: " + Bukkit.getVersion());
+ p.sendMessage("§6Java version: " + System.getProperty("java.version"));
+ p.sendMessage("§6used memory: " + (run.totalMemory() - run.freeMemory() / 1048576L) + " MB");
+ p.sendMessage("§6free memory: " + run.freeMemory() / 1048576L + " MB");
+ p.sendMessage("§6total memory: " + run.maxMemory() / 1048576L + " MB");
+ }
+
+ @Command(name = "troll", description = "troll other players", usage = "/troll ", rank = Rank.SrDeveloper, inGameOnly = true)
+ public void troll(CommandArgs args) {
+ args.getPlayer().sendMessage("§eavailable trolls: flip");
+ }
+
+ @Command(name = "troll.flip", description = "flip other players around", usage = "/troll flip ", rank = Rank.SrDeveloper, inGameOnly = true)
+ public void trollFlip(CommandArgs args) {
+ if (args.length() == 3) {
+ CustomPlayer t = CustomPlayer.getPlayer(args.getArg(2));
+ if (t != null && t != args.getPlayer()) {
+ if(trolledPlayers.contains(t)) {
+ t.getSpectatorTarget().remove();
+ t.setGameMode(ServerSettings.getGameMode());
+ trolledPlayers.remove(t);
+ }else {
+ trolledPlayers.add(t);
+ ArmorStand armorStand = t.getWorld().spawn(t.getLocation(), ArmorStand.class);
+ Location armorStandLocation = armorStand.getLocation();
+ t.setGameMode(GameMode.SPECTATOR);
+ t.setSpectatorTarget(armorStand);
+ new BukkitRunnable() {
+ public void run() {
+ armorStandLocation.setPitch(armorStandLocation.getPitch() + 0.5F);
+ armorStandLocation.setYaw(armorStandLocation.getYaw() - 0.5F);
+ ((CraftEntity) armorStand).getHandle().setPositionRotation(armorStandLocation.getX(), armorStandLocation.getY(), armorStandLocation.getZ(), armorStandLocation.getYaw(), armorStandLocation.getPitch());
+ }
+ }.runTaskTimer(Core.getInstance(), 0, 5);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/Fix.java b/src/main/java/eu/univento/core/commands/Fix.java
deleted file mode 100644
index a139d8e..0000000
--- a/src/main/java/eu/univento/core/commands/Fix.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * fixes players
- * @author joethei
- * @version 1.0
- */
-public class Fix extends AutoCommand{
-
- /**
- * @param plugin main class
- * @param command commons to execute
- * @param description describes the commons
- * @param aliases aliases of commons
- */
- public Fix(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
- //Messages msgs = new Messages(p);
- if(args.length == 0) {
- for(Player player : Bukkit.getOnlinePlayers()) {
- player.hidePlayer(p);
- player.showPlayer(p);
- }
- p.teleport(p.getLocation());
- //p.sendMessage(msgs.PREFIX() + msgs.Core_FIX_OWN());
- }
- if(args.length == 1) {
- if(Bukkit.getPlayer(args[0]) != null) {
- CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
- //Messages tMsgs = new Messages(t);
- if(t != p) {
- p.hidePlayer(t);
- p.showPlayer(t);
- p.teleport(p.getLocation());
- //p.sendMessage(msgs.Core_FIX_OTHER(t));
- //t.sendMessage(tMsgs.Core_FIX_BY_OTHER(p));
- }else {
- p.chat("/fix");
- }
- }else {
- //p.sendMessage(msgs.NOT_ONLINE(args[0]));
- }
- }
- }else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return true;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return Core.getOnlinePlayers().stream().map(CustomPlayer::getDisplayName).collect(Collectors.toList());
- }
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/GameMode.java b/src/main/java/eu/univento/core/commands/GameMode.java
deleted file mode 100644
index a1ea409..0000000
--- a/src/main/java/eu/univento/core/commands/GameMode.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * changes game modes
- * @author joethei
- * @version 1.0
- */
-public class GameMode extends AutoCommand{
-
- /**
- * @param plugin main class
- * @param description command description
- * @param command commons to execute
- * @param aliases aliases of commons
- */
- public GameMode(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
- //Messages msgs = new Messages(p);
- if(p.getDatabasePlayer().isAllowed(Rank.Builder)) {
- if(args.length == 1) {
- String mode = args[0];
- p.setGameMode(getModeFromString(mode));
- //p.sendMessage(msgs.Core_GM_CHANGED() + " auf " + p.getGameMode().name());
- }if(args.length == 0){
- //p.sendMessage(msgs.Core_GM_USAGE());
- }
- }else {
- //p.sendMessage(msgs.NO_PERMS());
- }
- }else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return true;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- List list = new ArrayList<>();
-
- list.add("0");
- list.add("1");
- list.add("2");
- list.add("3");
- list.add("Survival");
- list.add("Creative");
- list.add("Adventure");
- list.add("Spectator");
-
- return list;
- }
-
- /**
- * @param string Mode
- * @return GameMode
- */
- private org.bukkit.GameMode getModeFromString(String string) {
- switch(string) {
- case "0" : return org.bukkit.GameMode.SURVIVAL;
- case "1" : return org.bukkit.GameMode.CREATIVE;
- case "2": return org.bukkit.GameMode.ADVENTURE;
- case "3" : return org.bukkit.GameMode.SPECTATOR;
- case "Survial" : return org.bukkit.GameMode.SURVIVAL;
- case "Creative" : return org.bukkit.GameMode.CREATIVE;
- case "Adventure" : return org.bukkit.GameMode.ADVENTURE;
- case "Spectator" : return org.bukkit.GameMode.SPECTATOR;
- default: return org.bukkit.GameMode.SPECTATOR;
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/GlobalMute.java b/src/main/java/eu/univento/core/commands/GlobalMute.java
deleted file mode 100644
index d8bc7cd..0000000
--- a/src/main/java/eu/univento/core/commands/GlobalMute.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.server.ServerSettings;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.List;
-
-/**
- * mutes the whole server
- * @author joethei
- * @version 1.0
- */
-public class GlobalMute extends AutoCommand{
-
- /**
- * @param plugin main class
- * @param command commons to execute
- * @param description describes the commons
- * @param aliases aliases of commons
- */
- public GlobalMute(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
- //Messages msgs = new Messages(p);
- if(p.getDatabasePlayer().isAllowed(Rank.Supporter)) {
- if(ServerSettings.isMute()) {
- ServerSettings.setMute(false);
- //p.sendMessage(msgs.Core_GLOBALMUTE_OFF());
- }else {
- ServerSettings.setMute(true);
- //p.sendMessage(msgs.Core_GLOBALMUTE_ON());
- }
- }else {
- //p.sendMessage(msgs.NO_PERMS());
- }
- }else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return false;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return null;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/Hologram.java b/src/main/java/eu/univento/core/commands/Hologram.java
deleted file mode 100644
index cf89b6b..0000000
--- a/src/main/java/eu/univento/core/commands/Hologram.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2017 univento.eu - All rights reserved
- * You are not allowed to use, distribute or modify this code
- */
-
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.language.MessageConstant;
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.commons.utils.Strings;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.hologram.HologramManager;
-import eu.univento.core.api.player.CustomPlayer;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.List;
-
-/**
- * @author joethei
- * @version 0.1
- */
-public class Hologram extends AutoCommand {
-
- public Hologram(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(((Player) sender));
- if (p.getDatabasePlayer().isAllowed(Rank.JrBuilder)) {
- if (args.length == 0) {
- p.sendMessage("/hologram add ");
- p.sendMessage("/hologram remove ");
- p.sendMessage("/hologram list");
- }
- if (args.length == 1) {
- if (args[0].equalsIgnoreCase("list")) {
- HologramManager.getHolograms().forEach((s, hologram) -> p.sendMessage("§6" + s + hologram.getLocation().toString()));
- }
- }
- if (args.length == 2) {
- if (args[0].equalsIgnoreCase("remove")) {
- if (HologramManager.getHologram(args[1]) != null) {
- HologramManager.getHologram(args[1]).destroy();
- } else p.sendMessage("Dieses Hologram gibt es nicht");
- }
- } else {
- if (args[0].equalsIgnoreCase("add")) {
- if (HologramManager.getHologram(args[1]) != null) {
- p.sendMessage("Dieses Hologram gibt es schon");
- } else {
- String name = args[1];
- args = Strings.remove(args, "add");
- args = Strings.remove(args, name);
- new eu.univento.core.api.hologram.Hologram(name, args, p.getLocation());
- }
- }
- }
- } else {
- p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NO_PERMS);
- }/*
- }else sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- */
- }
- return true;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return null;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/HologramCommands.java b/src/main/java/eu/univento/core/commands/HologramCommands.java
new file mode 100644
index 0000000..e627f9f
--- /dev/null
+++ b/src/main/java/eu/univento/core/commands/HologramCommands.java
@@ -0,0 +1,51 @@
+package eu.univento.core.commands;
+
+import eu.univento.commons.player.rank.Rank;
+import eu.univento.commons.utils.Strings;
+import eu.univento.core.api.command.Command;
+import eu.univento.core.api.command.CommandArgs;
+import eu.univento.core.api.hologram.HologramManager;
+
+/**
+ * @author joethei
+ * @version 1.0
+ */
+public class HologramCommands {
+
+ @Command(name = "hologram", description = "create awesome holograms", rank = Rank.Builder, inGameOnly = true)
+ public void hologram(CommandArgs args) {
+ if(args.length() == 0) {
+ args.getPlayer().sendMessage("/hologram add ");
+ args.getPlayer().sendMessage("/hologram remove ");
+ args.getPlayer().sendMessage("/hologram list");
+ }
+ }
+
+ @Command(name = "hologram.list", description = "lists holograms", rank = Rank.Builder, inGameOnly = true)
+ public void hologramList(CommandArgs args) {
+ HologramManager.getHolograms().forEach((s, hologram) -> args.getPlayer().sendMessage("§6" + s +" | " + hologram.getLocation().toString()));
+ }
+
+ @Command(name = "hologram.add", description = "add holograms", rank = Rank.Builder, inGameOnly = true)
+ public void hologramAdd(CommandArgs args) {
+ if(args.length() > 2) {
+ if (HologramManager.getHologram(args.getArg(1)) != null) {
+ args.getPlayer().sendMessage("§cDieses Hologram gibt es schon");
+ } else {
+ String name = args.getArg(1);
+ String[] text = Strings.remove(args.getArgs(), "add");
+ text = Strings.remove(text, name);
+ new eu.univento.core.api.hologram.Hologram(name, text, args.getPlayer().getLocation()).showAll();
+ }
+ }
+ }
+
+ @Command(name = "hologram.remove", description = "remove holograms", rank = Rank.Builder, inGameOnly = true)
+ public void hologramRemove(CommandArgs args) {
+ if(args.length() == 2) {
+ if (HologramManager.getHologram(args.getArg(1)) != null) {
+ HologramManager.getHologram(args.getArg(1)).destroy();
+ } else args.getPlayer().sendMessage("§cDieses Hologram gibt es nicht");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/ModCommands.java b/src/main/java/eu/univento/core/commands/ModCommands.java
new file mode 100644
index 0000000..efdd34b
--- /dev/null
+++ b/src/main/java/eu/univento/core/commands/ModCommands.java
@@ -0,0 +1,46 @@
+package eu.univento.core.commands;
+
+import eu.univento.commons.player.rank.Rank;
+import eu.univento.core.Core;
+import eu.univento.core.api.command.Command;
+import eu.univento.core.api.command.CommandArgs;
+import eu.univento.core.api.player.CustomPlayer;
+import eu.univento.core.api.server.ServerSettings;
+import lombok.Getter;
+
+import java.util.ArrayList;
+
+/**
+ * @author joethei
+ * @version 1.0
+ */
+public class ModCommands {
+
+ @Getter private static ArrayList vanishedPlayers = new ArrayList<>();
+
+ @Command(name="chatclear", aliases = {"cc"}, description = "clears the chat", usage = "/clearchat", rank = Rank.JrModerator, inGameOnly = true)
+ public void chatClear(CommandArgs args) {
+ for(CustomPlayer player : Core.getOnlinePlayers()) {
+ if(!player.getDatabasePlayer().isAllowed(Rank.JrSupporter)) {
+ for(int i = 0; i <= 100; i++) player.sendMessage("");
+ }else player.sendMessage("§cDer Chat wurde von " + args.getPlayer().getDatabasePlayer().getRank().getColor() + args.getPlayer().getName() + " §cgeleert");
+ }
+ }
+
+ @Command(name="vanish", aliases={"v"}, description = "hide yourself", usage = "/vanish", rank = Rank.JrModerator, inGameOnly = true)
+ public void vanish(CommandArgs args) {
+ if(vanishedPlayers.contains(args.getPlayer())) {
+ for(CustomPlayer player : Core.getOnlinePlayers()) player.showPlayer(args.getPlayer());
+ vanishedPlayers.remove(args.getPlayer());
+ }else {
+ for(CustomPlayer player : Core.getOnlinePlayers()) player.hidePlayer(args.getPlayer());
+ vanishedPlayers.add(args.getPlayer());
+ }
+ }
+
+ @Command(name = "servermute", aliases = {"smute"}, description = "mute the entire server", usage = "/servermute", rank = Rank.SrModerator, inGameOnly = true)
+ public void serverMute(CommandArgs args) {
+ if(ServerSettings.isMute()) ServerSettings.setMute(false);
+ else ServerSettings.setMute(true);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/Nick.java b/src/main/java/eu/univento/core/commands/Nick.java
deleted file mode 100644
index f4a8cd2..0000000
--- a/src/main/java/eu/univento/core/commands/Nick.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.player.NickName;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.List;
-
-/**
- * nick commons
- * @author joethei
- * @version 1.0
- */
-public class Nick extends AutoCommand{
-
- /**
- * @param plugin main class
- * @param command commons to execute
- * @param description describes the commons
- * @param aliases aliases of commons
- */
- public Nick(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
- //Messages msgs = new Messages(p);
- if(p.getDatabasePlayer().isAllowed(Rank.VIP)) {
- if(p.getDatabasePlayer().getSettings().isNicked()) {
- p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).removeEntry(p.getDisplayName());
- p.getDatabasePlayer().getSettings().setNickStatus(false);
- p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).addEntry(p.getDisplayName());
- //p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_OFF());
- p.removeNickName();
- }else {
- p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).removeEntry(p.getDisplayName());
- p.getDatabasePlayer().getSettings().setNickStatus(true);
- p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).addEntry(p.getDisplayName());
- //p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_ON());
- String nick = NickName.getRandomNick();
- p.setNickName(nick);
- //Core.getDebugManager().sendOverlay("der Nick ist " + nick);
- }
- }else {
- //p.sendMessage(msgs.NO_PERMS());
- }
- }else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return true;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return null;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/PlayerCommands.java b/src/main/java/eu/univento/core/commands/PlayerCommands.java
new file mode 100644
index 0000000..6dbdbab
--- /dev/null
+++ b/src/main/java/eu/univento/core/commands/PlayerCommands.java
@@ -0,0 +1,47 @@
+package eu.univento.core.commands;
+
+import eu.univento.commons.player.language.MessageConstant;
+import eu.univento.core.Core;
+import eu.univento.core.api.command.Command;
+import eu.univento.core.api.command.CommandArgs;
+import eu.univento.core.api.command.Completer;
+import eu.univento.core.api.player.CustomPlayer;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author joethei
+ * @version 1.0
+ */
+public class PlayerCommands {
+
+ @Command(name = "fix", usage = "/fix", inGameOnly = true)
+ public void fix(CommandArgs args) {
+ if(args.length() == 0) {
+ for(CustomPlayer player : Core.getOnlinePlayers()) {
+ player.hidePlayer(args.getPlayer());
+ player.showPlayer(args.getPlayer());
+ }
+ args.getPlayer().teleport(args.getPlayer().getLocation());
+
+ } if(args.length() == 1) {
+ CustomPlayer t = CustomPlayer.getPlayer(args.getArg(0));
+ if(t != null) {
+ if(t != args.getPlayer()) {
+ args.getPlayer().hidePlayer(t);
+ args.getPlayer().showPlayer(t);
+ t.teleport(t.getLocation());
+ }else args.getPlayer().chat("/fix");
+
+ }else args.getPlayer().sendMessage(args.getPlayer().getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NOT_ONLINE));
+ }else {
+ args.getPlayer().chat("/fix");
+ }
+ }
+
+ @Completer(name = "fix")
+ public List fixCompleter(CommandArgs args) {
+ return Core.getOnlinePlayers().stream().map(CustomPlayer::getDisplayName).collect(Collectors.toList());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/RunAs.java b/src/main/java/eu/univento/core/commands/RunAs.java
deleted file mode 100644
index 56ca9df..0000000
--- a/src/main/java/eu/univento/core/commands/RunAs.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * lets other player run commands
- * @author joethei
- * @version 1.0
- */
-public class RunAs extends AutoCommand{
-
- /**
- * @param plugin main class
- * @param command commons to execute
- * @param description describes the commons
- * @param aliases aliases of commons
- */
- public RunAs(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
- //Messages msgs = new Messages(p);
- if(p.getDatabasePlayer().isAllowed(Rank.SrDeveloper)) {
- if(args.length >= 2) {
- CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
- if(t != null) {
- StringBuilder msg = new StringBuilder();
- for(int i = 1; i < args.length; i++) {
- msg.append(args[i]).append(" ");
- }
- t.chat(msg.toString());
- //p.sendMessage(msgs.Core_RUNAS_RUN(t));
- return true;
- }else {
- //p.sendMessage(msgs.NOT_ONLINE(args[0]));
- }
- }else {
- //p.sendMessage(msgs.Core_RUNAS_USAGE());
- }
- }else {
- //p.sendMessage(msgs.NO_PERMS());
- }
- }else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return false;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return Core.getOnlinePlayers().stream().map(CustomPlayer::getDisplayName).collect(Collectors.toList());
- }
-
-
-}
diff --git a/src/main/java/eu/univento/core/commands/SystemInfo.java b/src/main/java/eu/univento/core/commands/SystemInfo.java
deleted file mode 100644
index 27d4177..0000000
--- a/src/main/java/eu/univento/core/commands/SystemInfo.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.commons.server.TPS;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.List;
-
-/**
- * prints infos about the server
- * @author joethei
- * @version 1.0
- */
-public class SystemInfo extends AutoCommand{
-
- /**
- * @param plugin main class
- * @param command commons to execute
- * @param description describes the commons
- * @param aliases aliases of commons
- */
-
- public SystemInfo(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
- //Messages msgs = new Messages(p);
- if(p.getDatabasePlayer().isAllowed(Rank.Developer)) {
- Runtime run = Runtime.getRuntime();
- p.sendMessage("§6§l===SystemInfo <" + Bukkit.getServerName() + ">===");
- try {
- p.sendMessage("§6Server: " + InetAddress.getLocalHost().getHostName());
- } catch (UnknownHostException e) {
- e.printStackTrace();
- }
- p.sendMessage("§6TPS: " + TPS.getTPS());
- p.sendMessage("§6Spigot version: " + Bukkit.getVersion());
- p.sendMessage("§6Java version: " + System.getProperty("java.version"));
- p.sendMessage("§6OS: " + System.getProperty("os.name"));
- p.sendMessage("§6OS version: " + System.getProperty("os.version"));
- p.sendMessage("§6OS architecture: " + System.getProperty("os.arch"));
- p.sendMessage("§6User: " + System.getProperty("user.name"));
- p.sendMessage("§6used memory: " + (run.totalMemory() - run.freeMemory() / 1048576L) + " MB");
- p.sendMessage("§6free memory: " + run.freeMemory() / 1048576L + " MB");
- p.sendMessage("§6total memory: " + run.maxMemory() / 1048576L + " MB");
- p.sendMessage("§6avaiable cores: " + run.availableProcessors());
- p.sendMessage("§6System: " + System.getenv("COMPUTERNAME"));
- }else {
- //p.sendMessage(msgs.NO_PERMS());
- }
- }else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return false;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return null;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/Timeout.java b/src/main/java/eu/univento/core/commands/Timeout.java
deleted file mode 100644
index 9af5075..0000000
--- a/src/main/java/eu/univento/core/commands/Timeout.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.commons.player.language.MessageConstant;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.List;
-
-/**
- * @author joethei
- * @version 0.1
- */
-
-public class Timeout extends AutoCommand {
-
- public Timeout(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if (sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer((Player) sender);
- if (p.getDatabasePlayer().isAllowed(Rank.SrDeveloper)) {
- if (args.length == 1) {
- if (Bukkit.getPlayer(args[0]) != null) {
- CustomPlayer t = CustomPlayer.getPlayer(args[0]);
- if(Core.getTimeout().contains(p)) {
- Core.getTimeout().remove(p);
- }else{
- Core.getTimeout().add(p);
- }
- } else {
- p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NOT_ONLINE));
- }
- } else {
- p.sendMessage("Nicht genug Argumente");
- }
- } else {
- p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NO_PERMS));
- }
- } else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return true;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return null;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/VIPCommands.java b/src/main/java/eu/univento/core/commands/VIPCommands.java
new file mode 100644
index 0000000..d384461
--- /dev/null
+++ b/src/main/java/eu/univento/core/commands/VIPCommands.java
@@ -0,0 +1,26 @@
+package eu.univento.core.commands;
+
+import eu.univento.commons.player.rank.Rank;
+import eu.univento.core.api.command.Command;
+import eu.univento.core.api.command.CommandArgs;
+import eu.univento.core.api.player.CustomPlayer;
+import eu.univento.core.api.player.NickName;
+
+/**
+ * @author joethei
+ * @version 1.0
+ */
+public class VIPCommands {
+
+ @Command(name = "nick", description = "nick yourself", usage = "/nick", rank = Rank.VIP, inGameOnly = true)
+ public void nick(CommandArgs args) {
+ CustomPlayer p = args.getPlayer();
+ if(p.getDatabasePlayer().getSettings().isNicked()) {
+ p.getDatabasePlayer().getSettings().setNickStatus(false);
+ p.removeNickName();
+ }else {
+ p.getDatabasePlayer().getSettings().setNickStatus(true);
+ p.setNickName(NickName.getRandomNick());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/commands/Vanish.java b/src/main/java/eu/univento/core/commands/Vanish.java
deleted file mode 100644
index 940608a..0000000
--- a/src/main/java/eu/univento/core/commands/Vanish.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package eu.univento.core.commands;
-
-import eu.univento.commons.player.rank.Rank;
-import eu.univento.core.Core;
-import eu.univento.core.api.AutoCommand;
-import eu.univento.core.api.player.CustomPlayer;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * vanish players
- * @author joethei
- * @version 1.0
- */
-
-public class Vanish extends AutoCommand{
-
- /**
- * contains vanished players
- */
- private static final ArrayList players = new ArrayList<>();
- /**
- * @return vanished players
- */
- public static ArrayList getPlayers() {
- return players;
- }
-
- /**
- * @param plugin main class
- * @param command commons to execute
- * @param description describes the commons
- * @param aliases aliases of commons
- */
- public Vanish(Core plugin, String command, String description, String... aliases) {
- super(plugin, command, description, aliases);
- }
-
- @Override
- public boolean execute(CommandSender sender, String label, String[] args) {
- if(sender instanceof Player) {
- CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
- //Messages msgs = new Messages(p);
- if(p.getDatabasePlayer().isAllowed(Rank.JrSupporter)) {
- if(players.contains(p)) {
- for(Player players : Bukkit.getOnlinePlayers()) {
- players.showPlayer(p);
- }
- players.remove(p);
- //p.sendMessage(msgs.PREFIX() + msgs.Core_VANISH_OFF());
- }else {
- for(Player players : Bukkit.getOnlinePlayers()) {
- players.hidePlayer(p);
- }
- players.add(p);
- //p.sendMessage(msgs.PREFIX() + msgs.Core_VANISH_ON());
- }
- }else {
- //p.sendMessage(msgs.NO_PERMS());
- }
- }else {
- //sender.sendMessage(Messages.Console.NOT_A_PLAYER);
- }
- return false;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String label, String[] args) {
- return null;
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/listeners/Blocks.java b/src/main/java/eu/univento/core/listeners/Blocks.java
index 3fbae4d..bfc4698 100644
--- a/src/main/java/eu/univento/core/listeners/Blocks.java
+++ b/src/main/java/eu/univento/core/listeners/Blocks.java
@@ -1,7 +1,7 @@
package eu.univento.core.listeners;
import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.commands.Build;
+import eu.univento.core.commands.BuilderCommands;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -24,7 +24,7 @@ public class Blocks implements Listener{
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
- if(!Build.getPlayers().containsKey(p))
+ if(!BuilderCommands.getBuildPlayers().containsKey(p))
e.setCancelled(true);
}
@@ -35,7 +35,7 @@ public class Blocks implements Listener{
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
- if(!Build.getPlayers().containsKey(p))
+ if(!BuilderCommands.getBuildPlayers().containsKey(p))
e.setCancelled(true);
}
diff --git a/src/main/java/eu/univento/core/listeners/Chat.java b/src/main/java/eu/univento/core/listeners/Chat.java
index cd5d375..69a6a86 100644
--- a/src/main/java/eu/univento/core/listeners/Chat.java
+++ b/src/main/java/eu/univento/core/listeners/Chat.java
@@ -3,24 +3,16 @@ package eu.univento.core.listeners;
import eu.univento.commons.player.rank.Rank;
import eu.univento.commons.player.warn.WarnReason;
import eu.univento.core.Core;
-import eu.univento.core.api.blocks.MiniBlock;
-import eu.univento.core.api.customitems.swords.BestSwordEver;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.server.ServerSettings;
-import eu.univento.core.api.shop.ShopItem;
-import eu.univento.core.api.shop.ShopMenu;
-import eu.univento.core.api.shop.entity.ShopVillager;
import org.bukkit.ChatColor;
-import org.bukkit.Material;
import org.bukkit.Sound;
-import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
-import org.bukkit.inventory.ItemStack;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -44,23 +36,10 @@ public class Chat implements Listener {
public void onChat(AsyncPlayerChatEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
String message = e.getMessage();
+
if (p.getDatabasePlayer().isMuted()) {
e.setCancelled(true);
}
- //TODO: remove this, used for debugging
- if (message.equalsIgnoreCase("bestswordever")) {
- new BestSwordEver(p).addItem();
- }
- if (message.equalsIgnoreCase("shopvillager")) {
- ShopMenu menu = new ShopMenu(Core.getInstance(), "Shop Villager", ShopItem.TestItem);
- new ShopVillager(Core.getInstance(), "Shop Villager", p.getLocation(), Villager.Profession.LIBRARIAN, menu);
- }
- if (message.equalsIgnoreCase("miniblock")) {
- new MiniBlock(p.getLocation(), new ItemStack(Material.GRASS), 1);
- new MiniBlock(p.getEyeLocation(), new ItemStack(Material.DIAMOND_SWORD), 2);
- new MiniBlock(p.getWorld().getSpawnLocation(), new ItemStack(Material.WOOL), 3);
- }
-
if (ServerSettings.isMute()) {
if (!p.getDatabasePlayer().isAllowed(Rank.Sound)) {
e.setCancelled(true);
diff --git a/src/main/java/eu/univento/core/listeners/Events.java b/src/main/java/eu/univento/core/listeners/Events.java
index 404eee2..444da49 100644
--- a/src/main/java/eu/univento/core/listeners/Events.java
+++ b/src/main/java/eu/univento/core/listeners/Events.java
@@ -3,21 +3,23 @@ package eu.univento.core.listeners;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.SpectateManager;
import eu.univento.core.api.server.ServerSettings;
-import eu.univento.core.commands.Vanish;
+import eu.univento.core.commands.ModCommands;
import org.bukkit.Location;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.ExperienceOrb;
-import org.bukkit.entity.Player;
-import org.bukkit.entity.Tameable;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
-import org.bukkit.event.player.PlayerMoveEvent;
-import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.event.player.*;
import org.bukkit.event.server.ServerListPingEvent;
+import org.bukkit.material.Stairs;
import org.bukkit.util.Vector;
+import java.util.HashMap;
+
/**
* some basic events
*
@@ -27,6 +29,9 @@ import org.bukkit.util.Vector;
public class Events implements Listener {
+ private HashMap seats = new HashMap<>();
+ private HashMap seatEntities = new HashMap<>();
+
@EventHandler
public void onServerListPing(ServerListPingEvent e) {
e.setMotd(ServerSettings.getServerType().name() + ";" + (ServerSettings.isGame() ? ServerSettings.getGameState() : ""));
@@ -38,14 +43,54 @@ public class Events implements Listener {
p.setOpenInventory(false);
}
+ @EventHandler
+ public void onPlayerInteract(PlayerInteractEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ if(e.getClickedBlock() == null) return;
+ if(e.getClickedBlock().getRelative(BlockFace.DOWN).getType() != Material.ANVIL) return;
+ if(e.getClickedBlock().getState().getData() instanceof Stairs) {
+ loadSeat(p, e.getClickedBlock());
+ }
+ }
+
@EventHandler
public void onMove(PlayerMoveEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
if (p.getLocation().getY() <= 0) {
p.setVelocity(new Vector().setY(10.0D).multiply(1.0D));
p.setGliding(true);
-
}
+ if(e.getFrom().getY() != e.getTo().getY()) {
+ if(!p.isInsideVehicle() && seatEntities.containsKey(p)) {
+ if(seatEntities.get(p).isDead()) {
+ seatEntities.remove(p);
+ if(seats.get(p).getBlock().getState().getData() instanceof Stairs) loadSeat(p, seats.get(p).getBlock());
+ }else {
+ seatEntities.get(p).remove();
+ seatEntities.remove(p);
+ }
+ }
+ }
+ }
+
+ @EventHandler
+ public void onPlayerTeleport(PlayerTeleportEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ if(!p.isInsideVehicle() && seatEntities.containsKey(p)) {
+ seatEntities.get(p).remove();
+ seatEntities.remove(p);
+ seats.remove(p);
+ }
+ }
+
+ @EventHandler
+ public void onQuit(PlayerQuitEvent e) {
+ despawnSeat(CustomPlayer.getPlayer(e.getPlayer()));
+ }
+
+ @EventHandler
+ public void onKick(PlayerKickEvent e) {
+ despawnSeat(CustomPlayer.getPlayer(e.getPlayer()));
}
@EventHandler
@@ -55,7 +100,7 @@ public class Events implements Listener {
final Entity target = e.getTarget();
if (!(target instanceof Player)) return;
CustomPlayer p = CustomPlayer.getPlayer((Player) target);
- if (Vanish.getPlayers().contains(p) || SpectateManager.contains(p)) {
+ if (ModCommands.getVanishedPlayers().contains(p) || SpectateManager.contains(p)) {
if (entity instanceof Tameable) {
e.setTarget(null);
}
@@ -91,4 +136,35 @@ public class Events implements Listener {
}
}
+ private void loadSeat(CustomPlayer p, Block b) {
+ if(seats.containsKey(p) || seats.containsValue(b.getLocation())) return;
+ Location location = b.getLocation();
+ Stairs stairs = (Stairs) b.getState().getData();
+ if(stairs.getFacing() == null) return;
+ location.setDirection(new Vector(stairs.getFacing().getModX(), stairs.getFacing().getModY(), stairs.getFacing().getModZ()));
+ location.setX(location.getBlockX() + 0.5);
+ location.setY(location.getY() + 0.3);
+ location.setZ(location.getBlockZ() + 0.5);
+ ArmorStand stand = p.getWorld().spawn(location, ArmorStand.class);
+ stand.setVisible(false);
+ stand.setMarker(true);
+ stand.setSmall(true);
+ stand.setBasePlate(false);
+ stand.setGravity(false);
+ stand.setPassenger(p);
+ seats.put(p, b.getLocation());
+ seatEntities.put(p, stand);
+ }
+
+ public void despawnSeat(CustomPlayer p) {
+ if (seats.containsKey(p) && seatEntities.containsKey(p)) {
+ seatEntities.get(p).eject();
+ if (seatEntities.get(p) != null) {
+ seatEntities.get(p).remove();
+ }
+ seatEntities.remove(p);
+ seats.remove(p);
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/listeners/JoinQuit.java b/src/main/java/eu/univento/core/listeners/JoinQuit.java
index 07fa3ab..552964a 100644
--- a/src/main/java/eu/univento/core/listeners/JoinQuit.java
+++ b/src/main/java/eu/univento/core/listeners/JoinQuit.java
@@ -4,8 +4,8 @@ import eu.univento.commons.player.language.MessageConstant;
import eu.univento.core.Core;
import eu.univento.core.api.player.*;
import eu.univento.core.api.server.ServerSettings;
-import eu.univento.core.commands.Build;
-import eu.univento.core.commands.Vanish;
+import eu.univento.core.commands.BuilderCommands;
+import eu.univento.core.commands.ModCommands;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -45,10 +45,7 @@ public class JoinQuit implements Listener {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
p.getDatabasePlayer().load();
for (CustomPlayer player : Core.getOnlinePlayers()) {
- if (Vanish.getPlayers().contains(player)) {
- p.hidePlayer(player);
- }
- if (SpectateManager.contains(player)) {
+ if (ModCommands.getVanishedPlayers().contains(player) || SpectateManager.contains(player)) {
p.hidePlayer(player);
}
}
@@ -75,16 +72,18 @@ public class JoinQuit implements Listener {
p.setGameMode(ServerSettings.getGameMode());
p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
p.initScoreboard();
- //p.sendTabHeaderAndFooter(p.getMessages().Core_TAB_TITLE() + Bukkit.getServerName(), p.getMessages().TAB_PREFIX());
- p.getDatabasePlayer().getSettingsAsync().whenComplete((playerSettings, throwable) -> {
- if(playerSettings.isNicked() && !ServerSettings.isLobby()) {
- p.setNickName(NickName.getRandomNick());
- }
- });
+
+ p.sendTabHeaderAndFooter("Nothing to see here", "hello");
+
for (CustomPlayer player : Core.getOnlinePlayers()) {
p.getDatabasePlayer().getRankAsync().whenComplete((rank, throwable) -> player.getScoreboard().getTeam(rank.getTeam()).addEntry(p.getDisplayName()));
player.getDatabasePlayer().getRankAsync().whenComplete((rank, throwable) -> p.getScoreboard().getTeam(rank.getTeam()).addEntry(player.getDisplayName()));
}
+ p.getDatabasePlayer().getSettingsAsync().whenComplete((playerSettings, throwable) -> {
+ if(playerSettings.isNicked() && !ServerSettings.isLobby()) {
+ p.setNickName(NickName.getRandomNick());
+ }
+ });
p.setCollidable(false);
//p.setStoryResourcePack();
@@ -116,8 +115,8 @@ public class JoinQuit implements Listener {
@EventHandler
public void onQuit(PlayerQuitEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
- if (Build.getPlayers().containsKey(p))
- Build.getPlayers().remove(p);
+ if (BuilderCommands.getBuildPlayers().containsKey(p))
+ BuilderCommands.getBuildPlayers().remove(p);
p.getDatabasePlayer().getSettingsAsync().whenComplete((playerSettings, throwable) -> {
if(playerSettings.isNicked() && !ServerSettings.isLobby()) {
p.removeNickName();
diff --git a/src/main/java/eu/univento/core/listeners/NPCEvents.java b/src/main/java/eu/univento/core/listeners/NPCEvents.java
index 2d337a7..292b4e8 100644
--- a/src/main/java/eu/univento/core/listeners/NPCEvents.java
+++ b/src/main/java/eu/univento/core/listeners/NPCEvents.java
@@ -1,6 +1,20 @@
package eu.univento.core.listeners;
+import eu.univento.core.Core;
+import eu.univento.core.api.npc.NPC;
+import eu.univento.core.api.player.CustomPlayer;
+import net.minecraft.server.v1_11_R1.PacketPlayOutAnimation;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerKickEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+
+import java.util.Random;
/**
* @author joethei
@@ -9,4 +23,48 @@ import org.bukkit.event.Listener;
public class NPCEvents implements Listener {
+ @EventHandler
+ public void onJoin(PlayerJoinEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ for(NPC npc : NPC.getNpcs()) p.sendPacket(npc.packet);
+ }
+
+ @EventHandler
+ public void onPlayerInteract(PlayerInteractEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ if(e.getAction() == Action.LEFT_CLICK_AIR ||e.getAction() == Action.LEFT_CLICK_BLOCK) {
+ for(NPC npc : NPC.getNpcs()) {
+ if(npc.detect.equals(p)) {
+ PacketPlayOutAnimation animationPacket = new PacketPlayOutAnimation(npc.getBukkitEntity().getHandle(), 0);
+ for(CustomPlayer player : Core.getOnlinePlayers()) player.sendPacket(animationPacket);
+ }
+ }
+ }
+ if(p.getItemInHand() != null && p.getItemInHand().getType() == Material.NETHER_STAR && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
+ for(NPC npc : NPC.getNpcs()) if(npc.detect.equals(p)) {
+ npc.remove();
+ return;
+ }
+ Random random = new Random();
+ for(int i = 0; i <= 10; i++) {
+ NPC.spawn(p, p.getProfile(), new Location(p.getWorld(), p.getLocation().getX() + random.nextInt(10), p.getLocation().getY(), p.getLocation().getZ() - random.nextInt(10)));
+ }
+ }
+ }
+
+ @EventHandler
+ public void onPlayerQuit(PlayerQuitEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ for(NPC npc : NPC.getNpcs()) {
+ if (npc.detect.equals(p)) npc.remove();
+ }
+ }
+
+ @EventHandler
+ public void onPlayerKick(PlayerKickEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ for(NPC npc : NPC.getNpcs()) {
+ if(npc.detect.equals(p)) npc.remove();
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/listeners/PluginMessenger.java b/src/main/java/eu/univento/core/listeners/PluginMessenger.java
index fc37c99..3d29650 100644
--- a/src/main/java/eu/univento/core/listeners/PluginMessenger.java
+++ b/src/main/java/eu/univento/core/listeners/PluginMessenger.java
@@ -3,6 +3,7 @@ package eu.univento.core.listeners;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import eu.univento.commons.player.warn.WarnReason;
+import eu.univento.commons.server.ServerType;
import eu.univento.core.Core;
import eu.univento.core.api.player.CustomPlayer;
import org.bukkit.entity.Player;
@@ -39,7 +40,7 @@ public class PluginMessenger implements PluginMessageListener {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
- Core.getCommons().getLoggingHandler().getCore().info(p.getName() + " hat WDL installiert. Version : " + version);
+ Core.getCommons().getLoggingHandler().log(ServerType.getServerType(), p.getName() + " hat WDL installiert. Version : " + version);
p.sendMessage(p.getDatabasePlayer().getLanguage().getWord("Prefix") + p.getDatabasePlayer().getLanguage().getWord("Hack.WorldDownloader"));
}
if(channel.equals("WDL|CONTROL")) {
diff --git a/src/main/java/eu/univento/core/listeners/WeaponEvents.java b/src/main/java/eu/univento/core/listeners/WeaponEvents.java
index 3b5aed3..94d8c1f 100644
--- a/src/main/java/eu/univento/core/listeners/WeaponEvents.java
+++ b/src/main/java/eu/univento/core/listeners/WeaponEvents.java
@@ -23,7 +23,7 @@ public class WeaponEvents implements Listener {
if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
sword.primaryAttack();
}
- if(e.getAction() == Action.LEFT_CLICK_AIR ||e.getAction() == Action.LEFT_CLICK_BLOCK) {
+ if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
sword.secondaryAttack();
}
if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
diff --git a/src/main/java/eu/univento/core/listeners/WorkbenchEvents.java b/src/main/java/eu/univento/core/listeners/WorkbenchEvents.java
new file mode 100644
index 0000000..ec166eb
--- /dev/null
+++ b/src/main/java/eu/univento/core/listeners/WorkbenchEvents.java
@@ -0,0 +1,245 @@
+package eu.univento.core.listeners;
+
+import eu.univento.core.Core;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCloseEvent;
+import org.bukkit.event.inventory.InventoryDragEvent;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.player.PlayerKickEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Phloxz
+ * @version 1.0
+ */
+public class WorkbenchEvents implements Listener {
+ private static Map> workbenchList = new HashMap<>();
+ private static Map workbenchInventory = new HashMap<>();
+
+ @EventHandler(ignoreCancelled = true)
+ public void clickWorkbench(final PlayerInteractEvent e) {
+ final Player player = e.getPlayer();
+ if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock().getType() == Material.WORKBENCH) {
+ if (player.getOpenInventory() != null) {
+ player.getOpenInventory().close();
+ }
+ final Location location = e.getClickedBlock().getLocation();
+ if (workbenchList.containsKey(location)) {
+ new BukkitRunnable() {
+ public void run() {
+ Inventory inventory = null;
+ ItemStack[] items = null;
+ if (workbenchList.get(location).size() <= 1) {
+ items = workbenchInventory.get(location);
+ } else {
+ final Player randomPlayer = workbenchList.get(location).get(0);
+ inventory = randomPlayer.getOpenInventory().getTopInventory();
+ }
+ if (inventory != null && inventory.getType() == InventoryType.WORKBENCH) {
+ workbenchInventory.remove(location);
+ }
+ for (int i = 0; i <= 9; ++i) {
+ if (inventory != null) {
+ if (player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
+ player.getOpenInventory().getTopInventory().setItem(i, inventory.getItem(i));
+ }
+ } else if (items != null && items.length > i && items[i] != null && player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
+ player.getOpenInventory().getTopInventory().setItem(i, items[i]);
+ }
+ }
+ }
+ }.runTaskLater(Core.getInstance(), 2L);
+ workbenchList.get(location).add(player);
+ } else {
+ workbenchList.put(location, new ArrayList<>());
+ workbenchList.get(location).add(player);
+ }
+ }
+ }
+
+ @EventHandler
+ public void breakWorkbench(final BlockBreakEvent e) {
+ final Location location = e.getBlock().getLocation();
+ if (workbenchList.containsKey(location)) {
+ dropItems(location);
+ workbenchList.remove(location);
+ }
+ }
+
+ @EventHandler
+ public void clickWorkbench(final InventoryClickEvent e) {
+ if (e.getClickedInventory() == null) {
+ return;
+ }
+ if (e.getInventory() == null) {
+ return;
+ }
+ if (e.getClickedInventory().getType() == InventoryType.WORKBENCH && e.getSlot() >= 0 && e.getSlot() <= 9) {
+ final Player player = (Player) e.getWhoClicked();
+ Location location = null;
+ for (final Map.Entry> list : workbenchList.entrySet()) {
+ for (final Player otherPlayer : list.getValue()) {
+ if (otherPlayer.getOpenInventory().getTopInventory().equals(e.getClickedInventory())) {
+ location = list.getKey();
+ }
+ }
+ }
+ if (location != null) {
+ for (final Player otherPlayer2 : workbenchList.get(location)) {
+ new BukkitRunnable() {
+ public void run() {
+ for (int i = 0; i <= 9; ++i) {
+ if (otherPlayer2 != player) {
+ otherPlayer2.getOpenInventory().getTopInventory().setItem(i, player.getOpenInventory().getTopInventory().getItem(i));
+ }
+ }
+ }
+ }.runTaskLater(Core.getInstance(), 2L);
+ }
+ }
+ }
+ }
+
+ @EventHandler
+ public void dragEvent(final InventoryDragEvent e) {
+ if (e.getInventory() == null) {
+ return;
+ }
+ if (e.getInventory().getType() == InventoryType.WORKBENCH) {
+ final Player player = (Player) e.getWhoClicked();
+ Location location = null;
+ for (final Map.Entry> list : workbenchList.entrySet()) {
+ for (final Player otherPlayer : list.getValue()) {
+ if (otherPlayer.getOpenInventory().getTopInventory().equals(e.getInventory())) {
+ location = list.getKey();
+ }
+ }
+ }
+ if (location != null) {
+ for (final Player otherPlayer2 : workbenchList.get(location)) {
+ new BukkitRunnable() {
+ public void run() {
+ for (int i = 0; i <= 9; ++i) {
+ if (otherPlayer2 != player) {
+ otherPlayer2.getOpenInventory().getTopInventory().setItem(i, player.getOpenInventory().getTopInventory().getItem(i));
+ }
+ }
+ }
+ }.runTaskLater(Core.getInstance(), 2L);
+ }
+ }
+ }
+ }
+
+ @EventHandler
+ public void closeWorkbench(final InventoryCloseEvent e) {
+ Location location = null;
+ for (final Map.Entry> list : workbenchList.entrySet()) {
+ for (final Player otherPlayer : list.getValue()) {
+ if (otherPlayer.getOpenInventory().getTopInventory().equals(e.getInventory())) {
+ location = list.getKey();
+ }
+ }
+ }
+ if (location != null) {
+ final Player player = (Player) e.getPlayer();
+ workbenchList.get(location).remove(player);
+ if (workbenchList.get(location).size() == 0) {
+ if (e.getInventory().getType() == InventoryType.WORKBENCH) {
+ workbenchInventory.put(location, e.getInventory().getContents());
+ e.getInventory().clear();
+ }
+ } else {
+ e.getInventory().clear();
+ }
+ }
+ }
+
+ @EventHandler
+ public void quitWorkbench(final PlayerQuitEvent e) {
+ final Player player = e.getPlayer();
+ Location location = null;
+ for (final Map.Entry> list : workbenchList.entrySet()) {
+ for (final Player otherPlayer : list.getValue()) {
+ if (otherPlayer.equals(player)) {
+ location = list.getKey();
+ }
+ }
+ }
+ if (location != null) {
+ workbenchList.get(location).remove(player);
+ if (workbenchList.get(location).size() == 0 && player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
+ workbenchInventory.put(location, player.getOpenInventory().getTopInventory().getContents());
+ player.getOpenInventory().getTopInventory().clear();
+ }
+ }
+ }
+
+ @EventHandler
+ public void kickWorkbench(final PlayerKickEvent e) {
+ final Player player = e.getPlayer();
+ Location location = null;
+ for (final Map.Entry> list : workbenchList.entrySet()) {
+ for (final Player otherPlayer : list.getValue()) {
+ if (otherPlayer.equals(player)) {
+ location = list.getKey();
+ }
+ }
+ }
+ if (location != null) {
+ workbenchList.get(location).remove(player);
+ if (workbenchList.get(location).size() == 0 && player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
+ workbenchInventory.put(location, player.getOpenInventory().getTopInventory().getContents());
+ player.getOpenInventory().getTopInventory().clear();
+ }
+ }
+ }
+
+ private void dropItems(final Location loc) {
+ if (loc != null) {
+ if (workbenchInventory.containsKey(loc)) {
+ int id = 0;
+ for (final ItemStack item : workbenchInventory.get(loc)) {
+ if (item != null && item.getType() != Material.AIR && id > 0) {
+ loc.getWorld().dropItemNaturally(loc, item);
+ }
+ ++id;
+ }
+ }
+ } else {
+ for (final Map.Entry> entry : workbenchList.entrySet()) {
+ for (final Player player : entry.getValue()) {
+ if (player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
+ player.closeInventory();
+ }
+ }
+ }
+ for (final Map.Entry entry2 : workbenchInventory.entrySet()) {
+ final Location location = entry2.getKey();
+ int id2 = 0;
+ for (final ItemStack item2 : entry2.getValue()) {
+ if (item2 != null && item2.getType() != Material.AIR && id2 > 0) {
+ location.getWorld().dropItemNaturally(location, item2);
+ }
+ ++id2;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/listeners/cloud/Servers.java b/src/main/java/eu/univento/core/listeners/cloud/Servers.java
new file mode 100644
index 0000000..4f6506f
--- /dev/null
+++ b/src/main/java/eu/univento/core/listeners/cloud/Servers.java
@@ -0,0 +1,32 @@
+package eu.univento.core.listeners.cloud;
+
+import eu.univento.commons.event.MessageEvent;
+import eu.univento.commons.messaging.MessageHandler;
+import eu.univento.commons.server.ServerType;
+import org.bukkit.Bukkit;
+
+import java.util.regex.Pattern;
+
+/**
+ * @author joethei
+ * @version 1.0
+ */
+public class Servers {
+
+ public static void register() {
+ MessageHandler.registerListener("cloud.servers", new MessageEvent() {
+ @Override
+ public void onMessageReceived(String queue, String message) {
+ String[] split = message.split(Pattern.quote("|"));
+ if (split[1].equals("INFO") && split[2].equals(Bukkit.getServerName())) {
+ MessageHandler.sendMessage("cloud.servers", split[0] + "|" + Bukkit.getServerName() + "|" + ServerType.getServerType() + "|" + Bukkit.getOnlinePlayers().size());
+ }
+ }
+
+ @Override
+ public void onMessageSend(String queue, String message) {
+
+ }
+ });
+ }
+}
\ No newline at end of file