0

Clear on join #4

Merged
Minenash merged 5 commits from ClearOnJoin into master 2017-02-12 15:28:20 +00:00
2 changed files with 109 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import com.redstoner.modules.adminnotes.AdminNotes;
import com.redstoner.modules.chatalias.Chatalias;
import com.redstoner.modules.chatgroups.Chatgroups;
import com.redstoner.modules.check.Check;
import com.redstoner.modules.clearonjoin.ClearOnJoin;
import com.redstoner.modules.cycle.Cycle;
import com.redstoner.modules.damnspam.DamnSpam;
import com.redstoner.modules.imout.Imout;
@ -34,7 +35,7 @@ import com.redstoner.modules.webtoken.WebToken;
/** Main class. Duh.
*
* @author Pepich */
@Version(major = 1, minor = 4, revision = 0, compatible = -1)
@Version(major = 1, minor = 4, revision = 1, compatible = -1)
public class Main extends JavaPlugin
{
public static JavaPlugin plugin;
@ -51,6 +52,7 @@ public class Main extends JavaPlugin
ModuleLoader.addModule(AdminNotes.class);
// TODO: ModuleLoader.addModule(BlockplaceMods.class);
// TODO: ModuleLoader.addModule(Calc.class);
ModuleLoader.addModule(ClearOnJoin.class);
ModuleLoader.addModule(Chatalias.class);
ModuleLoader.addModule(Cycle.class);
ModuleLoader.addModule(Chatgroups.class);

View File

@ -0,0 +1,106 @@
package com.redstoner.modules.clearonjoin;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.json.simple.JSONArray;
import com.nemez.cmdmgr.Command;
import com.redstoner.misc.JsonManager;
import com.redstoner.misc.Main;
import com.redstoner.misc.Utils;
import com.redstoner.modules.Module;
public class ClearOnJoin implements Module, Listener{
boolean enabled = false;
private File listLocation = new File(Main.plugin.getDataFolder(), "clearonjoins.json");
private JSONArray list;
@SuppressWarnings("unchecked")
@Command(hook = "clearonjoin")
public void clearOnJoin(CommandSender sender, String player) {
list.add("!" + player.toLowerCase());
saveList();
Utils.sendMessage(sender, null, player +"'s inventory will be cleared next time he joins.");
}
@SuppressWarnings("unchecked")
@Command(hook = "clearonjoinself")
public void clearOnJoinSelf(CommandSender sender) {
String name = sender.getName().toLowerCase();
if(list.contains(name)) {
list.remove(name);
Utils.sendMessage(sender, null, "Your inventory will no longer be cleared apon joining");
saveList();
return;
}
list.add(name);
saveList();
Utils.sendMessage(sender, null, "Your inventory will now be cleared apon joining.");
}
@EventHandler
public void aponJoin(PlayerJoinEvent e)
{
Player player = e.getPlayer();
String playerName = player.getName().toLowerCase();
if(list.contains(playerName)) {
e.getPlayer().getInventory().clear();
Utils.sendMessage(e.getPlayer(), null, "Inventory Cleared.");
}
else if(list.contains("!" + playerName)){
e.getPlayer().getInventory().clear();
list.remove("!" + playerName);
saveList();
Utils.sendMessage(e.getPlayer(), null, "Inventory Cleared.");
}
}
public void saveList()
{
JsonManager.save(list, listLocation);
}
@Override
public void onEnable() {
enabled = true;
list = JsonManager.getArray(listLocation);
if (list == null) list = new JSONArray();
Bukkit.getServer().getPluginManager().registerEvents(this, Main.plugin);
}
@Override
public void onDisable() {
saveList();
enabled = false;
}
@Override
public boolean enabled() {
return enabled;
}
@Override
public String getCommandString() {
return "command clearonjoin {\n" +
" [string:name] {\n" +
" help Clears that players inventory the nect time they join.;\n" +
" run clearonjoin name;\n" +
" perm utils.clearonjoin.other;\n" +
" }\n" +
" [empty] {\n" +
" help Clears your inventory every time you join.;\n" +
" run clearonjoinself;\n" +
" perm utils.clearonjoin.self;\n" +
" }\n" +
"}";
}
}