From 76655a2c91d3bd45f82b5c0d448384c303a4d816 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 23 Jun 2016 12:42:22 +0200 Subject: [PATCH] Fixed things and added files... --- plugin.yml | 8 +- .../thebuttonmcchat/ChatProcessing.java | 6 +- .../thebuttonmcchat/PlayerListener.java | 14 ++- .../commands/TBMCCommandBase.java | 1 - .../commands/YeehawCommand.java | 37 ++++++++ .../commands/ucmds/CCommand.java | 57 ++++++++++++ .../commands/ucmds/KittycannonCommand.java | 91 +++++++++++++++++++ .../commands/ucmds/NameCommand.java | 37 ++++++++ .../commands/ucmds/OpmeCommand.java | 23 +++++ .../commands/ucmds/UCommand.java | 4 +- .../commands/ucmds/UCommandBase.java | 4 +- .../commands/ucmds/announce/EditCommand.java | 50 ++++++++++ .../commands/ucmds/announce/ListCommand.java | 33 +++++++ .../ucmds/announce/SetTimeCommand.java | 38 ++++++++ 14 files changed, 382 insertions(+), 21 deletions(-) create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/YeehawCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/CCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/KittycannonCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/NameCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/OpmeCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/EditCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/ListCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/SetTimeCommand.java diff --git a/plugin.yml b/plugin.yml index d14a0b7..f0e04c8 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ -name: TheButtonMCPlugin -main: io.github.norbipeti.thebuttonmc.PluginMain +name: TheButtonMCChatPlugin +main: io.github.norbipeti.thebuttonmcchat.PluginMain version: 4.0 commands: u: @@ -11,7 +11,7 @@ commands: alias: nrp unlol: description: Unlaugh the last laugh. - alias: unlaugh + alias: unlaugh mwiki: description: Search the wiki. usage: "&cUsage: /mwiki [query]&r" @@ -26,7 +26,7 @@ commands: description: Enable chat only mode. Useful for chat clients. usage: "&cUsage: /chatonly&r" author: NorbiPeti -depend: [Essentials, Towny, Minigames, Votifier, Factions, WorldGuard, WorldEdit, ProtocolLib, FastLogin, Vault, AuthMe] +depend: [Essentials, Towny, Minigames, Votifier, WorldGuard, WorldEdit, ProtocolLib, FastLogin, Vault, AuthMe] permissions: tbmc.admin: description: Gives access to /un- commands and /u admin commands diff --git a/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java b/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java index af85b5b..2d51939 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java +++ b/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java @@ -13,8 +13,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Objective; -import ru.tehkode.permissions.bukkit.PermissionsEx; - import com.earth2me.essentials.Essentials; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.object.Nation; @@ -456,13 +454,13 @@ public class ChatProcessing { } else if (currentchannel.equals(Channel.ModChat)) { try { if (player != null - && !PermissionsEx.getUser(player).inGroup("mod")) { + && !PluginMain.permission.playerInGroup(player, "mod")) { player.sendMessage("§cYou need to be a mod to use this channel."); return true; } Objective obj = PluginMain.SB.getObjective("mod"); for (Player p : PluginMain.GetPlayers()) { - if (PermissionsEx.getUser(p).inGroup("mod")) + if (PluginMain.permission.playerInGroup(p, "mod")) obj.getScore(p.getName()).setScore(1); else obj.getScore(p.getName()).setScore(0); diff --git a/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java b/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java index 0b1cf59..d4f3c58 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java +++ b/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java @@ -47,8 +47,6 @@ import au.com.mineauz.minigames.Minigames; import com.earth2me.essentials.Essentials; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.PlayerProfile; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.massivecore.ps.PS; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Town; @@ -358,7 +356,7 @@ public class PlayerListener implements Listener { .getPlayer().getDisplayName(), message)); } } - boolean tping = false; + /*boolean tping = false; boolean tphering = false; if (cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("call") || cmd.equalsIgnoreCase("ecall") @@ -368,7 +366,7 @@ public class PlayerListener implements Listener { tping = true; if (cmd.equalsIgnoreCase("tpahere") || cmd.equalsIgnoreCase("etpahere")) - tphering = true; + tphering = true;*/ /* * for (HelpTopic ht : PluginMain.Instance.getServer() @@ -384,7 +382,7 @@ public class PlayerListener implements Listener { * break; } */ - if (tphering) { + /*if (tphering) { Player target = Bukkit.getPlayer(event.getMessage() .substring(index + 1).split(" ")[0]); if (target != null @@ -396,12 +394,12 @@ public class PlayerListener implements Listener { "§cYou are not allowed to teleport players out from the Tower"); event.setCancelled(true); } - } + }*/ /* * for (String s : Bukkit.getCommandAliases().get("/tpahere")) { if * (cmd.equalsIgnoreCase(s)) { tping = true; break; } } */ - if (tping) { + /*if (tping) { if ( // MPlayer.get(event.getPlayer()).getFaction().getId().equalsIgnoreCase("nomansland")) // { @@ -414,7 +412,7 @@ public class PlayerListener implements Listener { "§cYou are not allowed to teleport to the Tower"); event.setCancelled(true); } - } + }*/ } if (cmd.equalsIgnoreCase("sethome")) { TownyUniverse tu = PluginMain.Instance.TU; diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/TBMCCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/TBMCCommandBase.java index 1e1a2d0..d2ac6bb 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/TBMCCommandBase.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/TBMCCommandBase.java @@ -1,6 +1,5 @@ package io.github.norbipeti.thebuttonmcchat.commands; -import java.util.ArrayList; import java.util.HashMap; import io.github.norbipeti.thebuttonmcchat.PluginMain; diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/YeehawCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/YeehawCommand.java new file mode 100644 index 0000000..fca74cb --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/YeehawCommand.java @@ -0,0 +1,37 @@ +package io.github.norbipeti.thebuttonmcchat.commands; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class YeehawCommand extends TBMCCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- YEEHAW command ----", + "This command makes you YEEHAW." }; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + for (Player p : PluginMain.GetPlayers()) { + p.playSound(p.getLocation(), "tbmc.yeehaw", 1f, 1f); + p.sendMessage("§b* " + + (sender instanceof Player ? ((Player) sender) + .getDisplayName() : sender.getName()) + " YEEHAWs."); + } //Even a cmdblock could yeehaw in theory + return true; + } + + @Override + public String GetCommandName() { + return "yeehaw"; + } + + @Override + public boolean GetPlayerOnly() { + return false; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/CCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/CCommand.java new file mode 100644 index 0000000..ea3b011 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/CCommand.java @@ -0,0 +1,57 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds; + +import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer; +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CCommand extends UCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Rainbow mode ----", + "This command allows you to talk in rainbow colors", + "You need to be a donator or a mod to use this command" }; + } + + @Override + public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + Player player = (Player) sender; + MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(player + .getUniqueId()); + if (args.length < 1) { + if (PluginMain.permission.has(player, "tbmc.rainbow")) { + p.RainbowPresserColorMode = !p.RainbowPresserColorMode; + p.OtherColorMode = ""; + if (p.RainbowPresserColorMode) + player.sendMessage("§eRainbow colors §aenabled."); + else + player.sendMessage("§eRainbow colors §cdisabled."); + } else { + player.sendMessage("§cYou don't have permission for this command. Donate to get it!"); + return true; + } + } else { + if (PluginMain.permission.has(player, "tbmc.admin")) { + p.RainbowPresserColorMode = false; + p.OtherColorMode = args[0]; + if (p.OtherColorMode.length() > 0) + player.sendMessage(String.format( + "§eMessage color set to %s", p.OtherColorMode)); + else + player.sendMessage("§eMessage color reset."); + } else { + player.sendMessage("§cYou don't have permission for this command."); + return true; + } + } + return true; + } + + @Override + public String GetUCommandName() { + return "c"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/KittycannonCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/KittycannonCommand.java new file mode 100644 index 0000000..29c91e4 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/KittycannonCommand.java @@ -0,0 +1,91 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import java.util.ArrayList; +import java.util.Random; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Ocelot; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import au.com.mineauz.minigames.MinigamePlayer; +import au.com.mineauz.minigames.Minigames; + +import com.earth2me.essentials.Mob; +import com.earth2me.essentials.Mob.MobException; + +public class KittycannonCommand extends UCommandBase { + + private static Random random = new Random(); + + public static String KittyCannonMinigame = "KittyCannon"; + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Kittycannon ----", + "This command is designed for the Kittycannon minigame" }; + } + + @Override + public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + Player player = (Player) sender; + MinigamePlayer mp = Minigames.plugin.pdata.getMinigamePlayer(player); + if (!(mp.isInMinigame() && mp.getMinigame().getName(false) + .equalsIgnoreCase(KittyCannonMinigame))) { + sender.sendMessage("§cYou can only use KittyCannon in it's minigame!"); + return true; + } + try { + final Mob cat = Mob.OCELOT; + final Ocelot ocelot = (Ocelot) cat.spawn(player.getWorld(), + player.getServer(), player.getEyeLocation()); + if (ocelot == null) { + return true; + } + final ArrayList lore = new ArrayList<>(); + lore.add(player.getName()); + final int i = random.nextInt(Ocelot.Type.values().length); + ocelot.setCatType(Ocelot.Type.values()[i]); + ocelot.setTamed(true); + ocelot.setBaby(); + ocelot.addPotionEffect(new PotionEffect( + PotionEffectType.DAMAGE_RESISTANCE, 5, 5)); + ocelot.setVelocity(player.getEyeLocation().getDirection() + .multiply(2)); + Bukkit.getScheduler().scheduleSyncDelayedTask(PluginMain.Instance, + new Runnable() { + @SuppressWarnings("deprecation") + @Override + public void run() { + final Location loc = ocelot.getLocation(); + ocelot.remove(); + loc.getWorld().createExplosion(loc, 0F); + final ItemStack head = new ItemStack( + Material.SKULL_ITEM, 1, (short) 3, (byte) 3); + SkullMeta im = (SkullMeta) head.getItemMeta(); + im.setDisplayName("§rOcelot Head"); + im.setOwner("MHF_Ocelot"); + im.setLore(lore); + head.setItemMeta(im); + loc.getWorld().dropItem(loc, head); + } + }, 20); + } catch (MobException e) { + } + return true; + } + + @Override + public String GetUCommandName() { + return "kittycannon"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/NameCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/NameCommand.java new file mode 100644 index 0000000..13e676f --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/NameCommand.java @@ -0,0 +1,37 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds; + +import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer; + +import org.bukkit.command.CommandSender; + +public class NameCommand extends UCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Get username ----", + "This command allows you to see the Reddit username of a player if they have one associated", + "Usage: /u name " }; + } + + @Override + public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + if (args.length == 1) { + return false; + } + MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromName(args[1]); + if (mp == null) { + sender.sendMessage("§cUnknown user (player has to be online): " + + args[1]); + return true; + } + sender.sendMessage("§bUsername of " + args[1] + ": " + mp.UserName); + return true; + } + + @Override + public String GetUCommandName() { + return "name"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/OpmeCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/OpmeCommand.java new file mode 100644 index 0000000..f5dd5af --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/OpmeCommand.java @@ -0,0 +1,23 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds; + +import org.bukkit.command.CommandSender; + +public class OpmeCommand extends UCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- OP me ----", "Totally makes you OP" }; + } + + @Override + public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + sender.sendMessage("It would be nice, wouldn't it?"); + return true; + } + + @Override + public String GetUCommandName() { + return "opme"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java index 5d3bcbe..e2f638b 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java @@ -2,8 +2,6 @@ package io.github.norbipeti.thebuttonmcchat.commands.ucmds; import org.bukkit.command.CommandSender; -import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; - public final class UCommand extends UCommandBase { @Override @@ -14,7 +12,7 @@ public final class UCommand extends UCommandBase { @Override public boolean OnUCommand(CommandSender sender, String alias, String[] args) { - return false; + return false; //TODO: Forward call to the correct handler } @Override diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java index 84eac45..73cc907 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java @@ -12,6 +12,8 @@ public abstract class UCommandBase extends TBMCCommandBase { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { + if (args.length == 0) + return false; return OnUCommand(sender, alias, Arrays.copyOfRange(args, 1, args.length)); } @@ -24,7 +26,7 @@ public abstract class UCommandBase extends TBMCCommandBase { return "u"; } - public abstract String GetUCommandName(); //TODO: Help for /u commands + public abstract String GetUCommandName(); // TODO: Help for /u commands @Override public boolean GetPlayerOnly() { diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/EditCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/EditCommand.java new file mode 100644 index 0000000..8d5929b --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/EditCommand.java @@ -0,0 +1,50 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandSender; + +public class EditCommand extends AnnounceCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Edit announcement ----", + "This command can only be used in a command block.", + "Usage: /u annonunce edit " }; + } + + @Override + public boolean OnAnnounceCommand(CommandSender sender, String alias, + String[] args) { + if (!(sender instanceof BlockCommandSender)) { + sender.sendMessage("§cError: This command can only be used from a command block. You can use add and remove, though it's not recommended."); + return true; + } + if (args.length < 4) { + return false; + } + StringBuilder sb1 = new StringBuilder(); + for (int i1 = 3; i1 < args.length; i1++) { + sb1.append(args[i1]); + if (i1 != args.length - 1) + sb1.append(" "); + } + String finalmessage1 = sb1.toString().replace('&', '§'); + int index = Integer.parseInt(args[2]); + if (index > 100) + return false; + while (PluginMain.AnnounceMessages.size() <= index) + PluginMain.AnnounceMessages.add(""); + PluginMain.AnnounceMessages.set(Integer.parseInt(args[2]), + finalmessage1); + sender.sendMessage("Announcement edited."); + return true; + } + + @Override + public String GetAnnounceCommandName() { + return "edit"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/ListCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/ListCommand.java new file mode 100644 index 0000000..f4c0920 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/ListCommand.java @@ -0,0 +1,33 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.CommandSender; + +public class ListCommand extends AnnounceCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- List announcements ----", + "This command lists the announcements and the time between them" }; + } + + @Override + public boolean OnAnnounceCommand(CommandSender sender, String alias, + String[] args) { + sender.sendMessage("§bList of announce messages:§r"); + sender.sendMessage("§bFormat: [index] message§r"); + int i = 0; + for (String message : PluginMain.AnnounceMessages) + sender.sendMessage("[" + i++ + "] " + message); + sender.sendMessage("§bCurrent wait time between announcements: " + + PluginMain.AnnounceTime / 60 / 1000 + " minute(s)§r"); + return true; + } + + @Override + public String GetAnnounceCommandName() { + return "list"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/SetTimeCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/SetTimeCommand.java new file mode 100644 index 0000000..89992d8 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/SetTimeCommand.java @@ -0,0 +1,38 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.CommandSender; + +public class SetTimeCommand extends AnnounceCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Set time ----", + "This command sets the time between the announcements", + "Usage: /u anonunce settime ", "Default: 15" }; + } + + @Override + public boolean OnAnnounceCommand(CommandSender sender, String alias, + String[] args) { + if (args.length < 3) { + return false; + } + try { + PluginMain.AnnounceTime = Integer.parseInt(args[0]) * 60 * 1000; + } catch (Exception e) { + sender.sendMessage("§cMinutes argument must be a number. Got: " + + args[0]); + return true; + } + sender.sendMessage("Time set between announce messages"); + return true; + } + + @Override + public String GetAnnounceCommandName() { + return "settime"; + } + +}