0

Merge branch 'master' of

https://github.com/RedstonerServer/New_JavaUtils.git

Conflicts:
	src/com/redstoner/coremods/moduleLoader/ModuleLoader.java
This commit is contained in:
Pepich 2017-03-29 09:56:21 +02:00
commit 6ad9e5e7e6
2 changed files with 95 additions and 9 deletions

View File

@ -105,6 +105,23 @@ public final class ModuleLoader implements CoreModule
if (modules.get(module))
continue;
enableLoadedModule(module);
try
{
if (module.onEnable())
{
if (VersionHelper.isCompatible(VersionHelper.create(2, 0, 0, -1), module.getClass()))
CommandManager.registerCommand(module.getCommandString(), module, Main.plugin);
modules.put(module, true);
Utils.info("Loaded module " + module.getClass().getName());
}
else
Utils.error("Failed to load module " + module.getClass().getName());
}
catch (Exception e)
{
Utils.error("Failed to load module " + module.getClass().getName());
e.printStackTrace();
}
}
Utils.info("Modules enabled, running post initialization.");
for (Module module : modules.keySet())
@ -157,6 +174,7 @@ public final class ModuleLoader implements CoreModule
Bukkit.getPluginManager().registerEvents((Listener) module, Main.plugin);
}
Utils.info("Enabled module " + module.getClass().getName());
Utils.info("Loaded module " + module.getClass().getName());
modules.put(module, true);
return true;
}
@ -178,6 +196,7 @@ public final class ModuleLoader implements CoreModule
Bukkit.getPluginManager().registerEvents((Listener) m, Main.plugin);
}
Utils.info("Loaded and enabled module " + m.getClass().getName());
Utils.info("Loaded module " + m.getClass().getName());
return true;
}
else

View File

@ -1,10 +1,12 @@
package com.redstoner.modules.essentials;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -56,7 +58,7 @@ public class Essentials implements Module
@Command(hook = "kickDef")
public void kick(CommandSender sender, String name)
{
kick(sender, name, EssentialsDefaults.kickMessage);
kick(sender, name, EssentialsDefaults.kick);
}
@Command(hook = "kick")
@ -64,7 +66,7 @@ public class Essentials implements Module
{
try
{
getPlayer(name).kick(getName(sender), reason);
getPlayer(name).kick(Utils.getName(sender), reason);
}
catch (PlayerNotFoundException e)
{
@ -72,6 +74,57 @@ public class Essentials implements Module
}
}
@Command(hook = "banDef")
public void ban(CommandSender sender, String name)
{
ban(sender, name, EssentialsDefaults.ban);
}
@Command(hook = "ban")
public void ban(CommandSender sender, String name, String reason)
{
try
{
getOfflinePlayer(name).ban(sender.getName(), reason, null);
}
catch (PlayerNotFoundException e)
{
Utils.sendErrorMessage(sender, null, e.getMessage());
}
}
@Command(hook = "tbanDefDR")
public void tempban(CommandSender sender, String name)
{
tempban(sender, name, EssentialsDefaults.tbanD, EssentialsDefaults.tbanR);
}
@Command(hook = "tbanDefR")
public void tbanD(CommandSender sender, String name, String duration)
{
tempban(sender, name, duration, EssentialsDefaults.tbanR);
}
@Command(hook = "tbanDefD")
public void tbanR(CommandSender sender, String name, String reason)
{
tempban(sender, name, EssentialsDefaults.tbanD, reason);
}
@Command(hook = "tban")
public void tempban(CommandSender sender, String name, String duration, String reason)
{
try
{
getOfflinePlayer(name).ban(Utils.getName(sender), reason,
new Date((new Date()).getTime() + Long.parseLong(duration)));
}
catch (PlayerNotFoundException | NumberFormatException e)
{
Utils.sendErrorMessage(sender, null, e.getMessage());
}
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e)
{
@ -109,13 +162,27 @@ public class Essentials implements Module
return getPlayer(player);
}
public static String getName(CommandSender sender)
public static EssentialsOfflinePlayer getOfflinePlayer(UUID uuid) throws PlayerNotFoundException
{
String name = "&9";
if (sender instanceof Player)
name += ((Player) sender).getDisplayName();
else
name += sender.getName();
return name;
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null)
throw new PlayerNotFoundException();
return getOfflinePlayer(player);
}
public static EssentialsOfflinePlayer getOfflinePlayer(OfflinePlayer player)
{
if (players.containsKey(player.getUniqueId()))
return players.get(player.getUniqueId());
return new EssentialsOfflinePlayer(player);
}
@Deprecated
public static EssentialsOfflinePlayer getOfflinePlayer(String name) throws PlayerNotFoundException
{
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
if (player == null)
throw new PlayerNotFoundException();
return getOfflinePlayer(player);
}
}