0
This commit is contained in:
Pepich 2017-02-18 18:10:24 +01:00
commit 208ae3f256
5 changed files with 558 additions and 1 deletions

View File

@ -9,11 +9,14 @@ import com.redstoner.misc.mysql.MysqlHandler;
import com.redstoner.modules.abot.Abot;
import com.redstoner.modules.adminchat.Adminchat;
import com.redstoner.modules.adminnotes.AdminNotes;
import com.redstoner.modules.challenge.Challenge;
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.illumination.Illumination;
import com.redstoner.modules.imout.Imout;
import com.redstoner.modules.lagchunks.LagChunks;
import com.redstoner.modules.loginsecurity.LoginSecurity;
@ -21,6 +24,7 @@ import com.redstoner.modules.mentio.Mentio;
import com.redstoner.modules.misc.Misc;
import com.redstoner.modules.motd.Motd;
import com.redstoner.modules.nametags.Nametags;
import com.redstoner.modules.naming.Naming;
import com.redstoner.modules.pmtoggle.Pmtoggle;
import com.redstoner.modules.reports.Reports;
import com.redstoner.modules.saylol.Saylol;
@ -34,7 +38,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,12 +55,15 @@ public class Main extends JavaPlugin
ModuleLoader.addModule(AdminNotes.class);
// TODO: ModuleLoader.addModule(BlockplaceMods.class);
// TODO: ModuleLoader.addModule(Calc.class);
ModuleLoader.addModule(Challenge.class);
ModuleLoader.addModule(ClearOnJoin.class);
ModuleLoader.addModule(Chatalias.class);
ModuleLoader.addModule(Cycle.class);
ModuleLoader.addModule(Chatgroups.class);
ModuleLoader.addModule(Check.class);
ModuleLoader.addModule(DamnSpam.class);
// TODO: ModuleLoader.addModule(Friends.class);
ModuleLoader.addModule(Illumination.class);
// TODO: ModuleLoader.addModule(Imbusy.class);
ModuleLoader.addModule(Imout.class);
ModuleLoader.addModule(LagChunks.class);
@ -64,6 +71,7 @@ public class Main extends JavaPlugin
ModuleLoader.addModule(Mentio.class);
ModuleLoader.addModule(Misc.class);
ModuleLoader.addModule(Motd.class);
ModuleLoader.addModule(Naming.class);
ModuleLoader.addModule(Nametags.class);
ModuleLoader.addModule(Pmtoggle.class);
ModuleLoader.addModule(Reports.class);

View File

@ -0,0 +1,266 @@
package com.redstoner.modules.challenge;
import java.io.File;
import java.util.Random;
import org.bukkit.command.CommandSender;
import org.json.simple.JSONArray;
import com.nemez.cmdmgr.Command;
import com.redstoner.annotations.Version;
import com.redstoner.misc.JsonManager;
import com.redstoner.misc.Main;
import com.redstoner.misc.Utils;
import com.redstoner.modules.Module;
@Version(major = 1, minor = 0, revision = 0, compatible = 1)
public class Challenge implements Module
{
private boolean enabled = false;
private File challengeLocation = new File(Main.plugin.getDataFolder(), "challenges.json");
private JSONArray challenges;
@Override
public void onEnable()
{
challenges = JsonManager.getArray(challengeLocation);
if (challenges == null)
challenges = new JSONArray();
enabled = true;
}
@Override
public void onDisable()
{
saveChallenges();
enabled = false;
}
@Override
public boolean enabled()
{
return enabled;
}
@SuppressWarnings("unchecked")
@Command(hook = "addchallenge")
public boolean addChallenge(CommandSender sender, String text)
{
if (challenges.contains(text))
Utils.sendErrorMessage(sender, null, "That challenge already exists!");
else
{
Utils.sendMessage(sender, null, "Successfully added a new challenge!");
challenges.add("&a" + text);
saveChallenges();
}
return true;
}
@Command(hook = "delchallenge")
public boolean delChallenge(CommandSender sender, int id)
{
if (id < 0 || id >= challenges.size())
{
Utils.sendErrorMessage(sender, null, "The ID must be at least 0 and at most " + challenges.size());
return true;
}
Utils.sendMessage(sender, null, "Successfully deleted the challenge: " + challenges.remove(id), '&');
saveChallenges();
return true;
}
@SuppressWarnings("unchecked")
@Command(hook = "setchallenge")
public boolean setChallenge(CommandSender sender, int id, String text)
{
if (id < 0 || id >= challenges.size())
{
Utils.sendErrorMessage(sender, null, "The ID must be at least 0 and at most " + challenges.size());
return true;
}
Utils.sendMessage(sender, null, "Successfully changed the challenge: &a" + challenges.get(id) + " &7to: &e" + text, '&');
challenges.set(id, text);
saveChallenges();
return true;
}
@Command(hook = "challengeid")
public boolean challengeId(CommandSender sender, int id)
{
if (id < 0 || id >= challenges.size())
{
Utils.sendErrorMessage(sender, null, "The ID must be at least 0 and at most " + (challenges.size() - 1));
return true;
}
Utils.sendMessage(sender, null, challenges.get(id) + "", '&');
return true;
}
@Command(hook = "challenge")
public boolean challenge(CommandSender sender)
{
int id = (new Random()).nextInt(challenges.size());
Utils.sendMessage(sender, null, challenges.get(id) + "", '&');
return true;
}
@Command(hook = "listchallenges")
public boolean listChallenges(CommandSender sender, int page)
{
page = page - 1;
int start = page * 10;
int end = start + 10;
int pages = (int) Math.ceil(challenges.size() / 10d);
if (start < 0)
{
Utils.sendErrorMessage(sender, null, "Page number too small, must be at least 0!");
return true;
}
if (start > challenges.size())
{
Utils.sendErrorMessage(sender, null, "Page number too big, must be at most " + pages + "!");
return true;
}
Utils.sendModuleHeader(sender);
Utils.sendMessage(sender, "", "&ePage " + (page + 1) + "/" + pages + ":", '&');
for (int i = start; i < end && i < challenges.size(); i++)
Utils.sendMessage(sender, "", "&a" + i + "&8: &e" + challenges.get(i), '&');
return true;
}
@Command(hook = "listchallengesdef")
public boolean listChallengesDefault(CommandSender sender)
{
return listChallenges(sender, 1);
}
@Command(hook = "searchchallenge")
public boolean search(CommandSender sender, boolean insensitive, String text)
{
Utils.sendModuleHeader(sender);
boolean found = false;
if (insensitive)
{
text = text.toLowerCase();
for (int i = 0; i < challenges.size(); i++)
{
if (((String) challenges.get(i)).toLowerCase().contains(text))
{
Utils.sendMessage(sender, "", "&a" + i + "&8: &e" + challenges.get(i), '&');
found = true;
}
}
}
else
{
for (int i = 0; i < challenges.size(); i++)
{
if (((String) challenges.get(i)).contains(text))
{
Utils.sendMessage(sender, "", "&a" + i + "&8: &e" + challenges.get(i), '&');
found = true;
}
}
}
if (!found)
{
Utils.sendMessage(sender, "", "&cCouldn't find any matching challenges.", '&');
}
return true;
}
@Command(hook = "matchchallenge")
public boolean match(CommandSender sender, boolean insensitive, String regex)
{
Utils.sendModuleHeader(sender);
boolean found = false;
if (insensitive)
{
regex = regex.toLowerCase();
for (int i = 0; i < challenges.size(); i++)
{
if (((String) challenges.get(i)).toLowerCase().matches(regex))
{
Utils.sendMessage(sender, "", "&a" + i + ": " + challenges.get(i), '&');
found = true;
}
}
}
else
{
for (int i = 0; i < challenges.size(); i++)
{
if (((String) challenges.get(i)).matches(regex))
{
Utils.sendMessage(sender, "", "&a" + i + ": " + challenges.get(i), '&');
found = true;
}
}
}
if (!found)
{
Utils.sendMessage(sender, "", "&cCouldn't find any matching challenges.", '&');
}
return true;
}
public void saveChallenges()
{
JsonManager.save(challenges, challengeLocation);
}
// @noformat
@Override
public String getCommandString()
{
return "command challenge {\n" +
" add [string:text...] {\n" +
" help Adds a challenge.;\n" +
" run addchallenge text;\n" +
" perm utils.challenge.add;\n" +
" }\n" +
" del [int:id] {\n" +
" help Removes a challenge.;\n" +
" run delchallenge id;\n" +
" perm utils.challenge.admin;\n" +
" }\n" +
" set [int:id] [string:text...] {\n" +
" help Sets a challenge.;\n" +
" run setchallenge id text;\n" +
" perm utils.challenge.admin;\n" +
" }\n" +
" id [int:id] {\n" +
" help Get a paticular challenge.;\n" +
" run challengeid id;\n" +
" perm utils.challenge.id;\n" +
" }\n" +
" list [int:page] {\n" +
" help Shows challenges.;\n" +
" run listchallenges page;\n" +
" perm utils.challenge.list;\n" +
" }\n" +
" list {\n" +
" help Shows challenges.;\n" +
" run listchallengesdef;\n" +
" perm utils.challenge.list;\n" +
" }\n" +
" search [flag:-i] [string:text...] {\n" +
" help Search challenges.;\n" +
" run searchchallenge -i text;\n" +
" perm utils.challenge.search;\n" +
" }\n" +
" match [flag:-i] [string:regex...] {\n" +
" help Search challenges. But better.;\n" +
" run matchchallenge -i regex;\n" +
" perm utils.challenge.match;\n" +
" }\n" +
" [empty] {\n" +
" help Gives a challenge.;\n" +
" run challenge;\n" +
" perm utils.challenge;\n" +
" }\n" +
"}";
}
// @format
}

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" +
"}";
}
}

View File

@ -0,0 +1,62 @@
package com.redstoner.modules.illumination;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.nemez.cmdmgr.Command;
import com.redstoner.annotations.Version;
import com.redstoner.misc.Utils;
import com.redstoner.modules.Module;
@Version(major = 1, minor = 0, revision = 0, compatible = 1)
public class Illumination implements Module{
boolean enabled = false;
PotionEffect effect = new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, false, false);
@Command(hook = "illuminate")
public void illuminate(CommandSender sender) {
Player player = (Player) sender;
if(player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
Utils.sendMessage(sender, null, "Night Vision Disabled.");
}
else {
player.addPotionEffect(effect, true);
Utils.sendMessage(sender, null, "Night Vision Enabled.");
}
}
@Override
public void onEnable() {
enabled = true;
}
@Override
public void onDisable() {
enabled = false;
}
@Override
public boolean enabled() {
return enabled;
}
@Override
public String getCommandString() {
return "command nightvision {\n" +
" [empty] {\n" +
" run illuminate;\n" +
" type player;\n" +
" help Gives the player infinte night vision;\n" +
" perm utils.illuminate;\n" +
" }\n" +
"}\n" +
"\n" +
"}";
}
}

View File

@ -0,0 +1,115 @@
package com.redstoner.modules.naming;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.nemez.cmdmgr.Command;
import com.redstoner.misc.Utils;
import com.redstoner.modules.Module;
import net.md_5.bungee.api.ChatColor;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.ChatMessage;
import net.minecraft.server.v1_11_R1.ContainerAnvil;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow;
public class Naming implements Module{
boolean enabled = false;
@Command(hook = "anvil")
public void anvil(CommandSender sender) {
EntityPlayer p = ((CraftPlayer) sender).getHandle();
AnvilContainer container = new AnvilContainer(p);
int c = p.nextContainerCounter();
p.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c,"minecraft:anvil",new ChatMessage("Repairing",new Object[]{}),0));
p.activeContainer = container;
p.activeContainer.windowId = c;
p.activeContainer.addSlotListener(p);
}
@Command(hook = "name")
public void name(CommandSender sender, String name){
name = ChatColor.translateAlternateColorCodes('&', name);
ItemStack item = ((Player)sender).getInventory().getItemInMainHand();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
item.setItemMeta(meta);
Utils.sendMessage(sender, null, "Name set to " + name);
}
@Command(hook = "lore")
public void lore(CommandSender sender, String name){
List<String> lore = new ArrayList<String>();
name = ChatColor.translateAlternateColorCodes('&', name);
lore.add(name);
ItemStack item = ((Player)sender).getInventory().getItemInMainHand();
ItemMeta meta = item.getItemMeta();
meta.setLore(lore);
item.setItemMeta(meta);
item.getItemMeta().setLore(lore);
Utils.sendMessage(sender, null, "Lore set to " + name);
}
public class AnvilContainer extends ContainerAnvil {
public AnvilContainer(EntityHuman entity) {
super(entity.inventory, entity.world, new BlockPosition(0, 0, 0), entity);
}
public boolean a(EntityHuman entityhuman) {
return true;
}
}
@Override
public void onEnable() {
enabled = true;
}
@Override
public void onDisable() {
enabled = false;
}
@Override
public boolean enabled() {
return enabled;
}
@Override
public String getCommandString() {
// TODO Auto-generated method stub
return "command anvil {\n" +
" [empty] {\n" +
" run anvil;\n" +
" type player;\n" +
" help Opens anvil GUI.;\n" +
" perm utils.anvil;\n" +
" }\n" +
"}\n" +
"\n" +
"command name {\n" +
" [string:name...] {\n" +
" run name name;\n" +
" type player;\n" +
" help Names item in hand.;\n" +
" perm utils.name;\n" +
" }\n" +
"}\n" +
"\n" +
"command lore {\n" +
" [string:name...] {\n" +
" run lore name;\n" +
" type player;\n" +
" help Adds lore to item in hand.;\n" +
" perm utils.lore;\n" +
" }\n" +
"}";
}
}