Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Making progress, still far from finished though

  • Loading branch information...
commit e27c1d077a03ff82ce66830cd2982fd88e18252e 1 parent 0cd2a79
@GuntherDW authored
Showing with 797 additions and 1,015 deletions.
  1. +3 −3 src/com/guntherdw/bukkit/tweakcraft/Chat/ChatHandler.java
  2. +68 −7 src/com/guntherdw/bukkit/tweakcraft/Chat/ChatMode.java
  3. +9 −27 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java
  4. +9 −17 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/GroupChat.java
  5. +21 −38 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/LocalChat.java
  6. +10 −29 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/RegionChat.java
  7. +26 −40 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/WorldChat.java
  8. +21 −28 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/ZoneChat.java
  9. +5 −3 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/AdminCommands.java
  10. +145 −425 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/ChatCommands.java
  11. +30 −26 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/EssentialsCommands.java
  12. +3 −0  src/com/guntherdw/bukkit/tweakcraft/Configuration/ConfigurationHandler.java
  13. +1 −1  src/com/guntherdw/bukkit/tweakcraft/DataSources/PersistenceClass/ChatChannel.java
  14. +1 −1  src/com/guntherdw/bukkit/tweakcraft/DataSources/PersistenceClass/PlayerHistoryInfo.java
  15. +1 −1  src/com/guntherdw/bukkit/tweakcraft/DataSources/PersistenceClass/PlayerOptions.java
  16. +10 −11 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftBlockListener.java
  17. +258 −247 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java
  18. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Packages/Argument.java
  19. +2 −2 src/com/guntherdw/bukkit/tweakcraft/Packages/Ban.java
  20. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Packages/Item.java
  21. +30 −0 src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java
  22. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Packages/LockdownLocation.java
  23. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Packages/TamerMode.java
  24. +57 −43 src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java
  25. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Worlds/Generators/FlatGen.java
  26. +82 −61 src/com/guntherdw/bukkit/tweakcraft/Worlds/TweakWorld.java
View
6 src/com/guntherdw/bukkit/tweakcraft/Chat/ChatHandler.java
@@ -33,9 +33,9 @@
private TweakcraftUtils plugin;
private AntiSpam antispam = null;
- public Map<String, ChatMode> chatmodes = new HashMap<String, ChatMode>();
- public Map<String, String> playerchatmode = new HashMap<String, String>();
- public Map<String, Long> mutedPlayers = new HashMap<String, Long>();
+ private Map<String, ChatMode> chatmodes = new HashMap<String, ChatMode>();
+ private Map<String, String> playerchatmode = new HashMap<String, String>();
+ private Map<String, Long> mutedPlayers = new HashMap<String, Long>();
public ChatHandler(TweakcraftUtils instance) {
View
75 src/com/guntherdw/bukkit/tweakcraft/Chat/ChatMode.java
@@ -18,15 +18,32 @@
package com.guntherdw.bukkit.tweakcraft.Chat;
+import com.avaje.ebean.text.StringFormatter;
+import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.logging.Logger;
/**
* @author GuntherDW
*/
-public interface ChatMode {
+public abstract class ChatMode {
+
+ protected Set<String> subscribers;
+ protected ChatHandler chathandler;
+ protected String chatModeName = null;
+ protected Logger logger = Logger.getLogger("Minecraft");
+
+ public ChatMode(ChatHandler instance) {
+ subscribers = new HashSet<String>();
+ this.chathandler = instance;
+ }
/**
* Sends a message in the chosen method
@@ -35,21 +52,35 @@
* @param message
* @return
*/
- public abstract boolean sendMessage(CommandSender sender, String message);
+ public boolean sendMessage(CommandSender sender, String message) {
+
+ String playerMessage = String.format(getChatFormatString(), sender instanceof Player?((Player)sender).getDisplayName(): ChatColor.LIGHT_PURPLE+"CONSOLE"+ChatColor.WHITE, message);
+ for(Player player : getRecipients(sender)) {
+ player.sendMessage(playerMessage);
+ }
+
+ logChat(sender, message);
+
+ return true;
+ }
/**
* Returns a list of players that will get the message
*
* @return
*/
- public abstract List<Player> getRecipients(CommandSender sender);
+ public abstract Set<Player> getRecipients(CommandSender sender);
/**
* Tries to remove a recipient
*
* @param player
*/
- public abstract void addRecipient(String player);
+ public void addRecipient(String player) {
+ if (!subscribers.contains(player)) {
+ subscribers.add(player);
+ }
+ }
/**
* Broadcasts a message in the current ChatMode
@@ -65,14 +96,20 @@
*
* @param player
*/
- public abstract void removeRecipient(String player);
+ public void removeRecipient(String player) {
+ if (subscribers.contains(player)) {
+ subscribers.remove(player);
+ }
+ }
/**
* Gets the current subscribed list
*
* @return
*/
- public abstract List<String> getSubscribers();
+ public Set<String> getSubscribers() {
+ return this.subscribers;
+ }
/**
* Shows a little description about the ChatMode
@@ -86,7 +123,10 @@
*
* @return enabled
*/
- public abstract boolean isEnabled();
+ public boolean isEnabled() {
+ return false;
+ }
+
/**
* Gets the ChatMode's color
@@ -101,4 +141,25 @@
* @return the prefix
*/
public abstract String getPrefix();
+
+ /**
+ *
+ */
+ public String getLoggingFormatString() {
+ String name = this.chatModeName==null?getClass().getSimpleName():chatModeName;
+ return name+": <%1$s> %2$s";
+ }
+
+ public String getChatFormatString() {
+ String prefix = getPrefix();
+ return (prefix!=null?prefix+": ":"")+ "[%1$s] %2$s";
+ }
+
+ public void logChat(CommandSender sender, String message) {
+ String logFormat = getLoggingFormatString();
+ if(logFormat!=null) {
+ String logMessage = String.format(logFormat, sender instanceof Player?((Player)sender).getName(): "CONSOLE", message);
+ logger.info(logMessage);
+ }
+ }
}
View
36 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java
@@ -28,24 +28,21 @@
import org.bukkit.entity.Player;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* @author GuntherDW
*/
-public class AdminChat implements ChatMode {
+public class AdminChat extends ChatMode {
- /* TweakcraftUtils stuff */
-
- private List<String> subscribers;
- private TweakcraftUtils plugin;
- private ChatHandler chathandler;
private CraftIRC circ;
+ private TweakcraftUtils plugin;
public AdminChat(ChatHandler instance) {
- subscribers = new ArrayList<String>();
- this.chathandler = instance;
- this.plugin = chathandler.getTCUtilsInstance();
+ super(instance);
+ this.plugin = instance.getTCUtilsInstance();
if (plugin.getConfigHandler().enableIRC) {
this.circ = plugin.getCraftIRC();
circ.registerEndPoint("tcutilsadmin", plugin.getAdminEndPoint());
@@ -130,8 +127,8 @@ public boolean broadcastMessageRealAdmins(String message) {
return true;
}
- public List<Player> getRecipients(CommandSender sender) {
- List<Player> recp = new ArrayList<Player>();
+ public Set<Player> getRecipients(CommandSender sender) {
+ Set<Player> recp = new HashSet<Player>();
for (String m : subscribers) {
Player p = plugin.getServer().getPlayer(m);
if (p != null)
@@ -155,12 +152,6 @@ public boolean isOnList(CommandSender sender) {
}
}
- public void addRecipient(String player) {
- if (!subscribers.contains(player)) {
- subscribers.add(player);
- }
- }
-
public List<Player> getAdmins() {
List<Player> recp = new ArrayList<Player>();
for (Player p : plugin.getServer().getOnlinePlayers()) {
@@ -178,16 +169,6 @@ public void addRecipient(String player) {
return admins;
}
- public void removeRecipient(String player) {
- if (subscribers.contains(player)) {
- subscribers.remove(player);
- }
- }
-
- public List<String> getSubscribers() {
- return subscribers;
- }
-
public String getDescription() {
return "Admin chat (needs permissions!)";
}
@@ -199,6 +180,7 @@ public boolean sendToRealAdmins(CommandSender sender, String message) {
return true;
}
+ @Override
public boolean isEnabled() {
return true;
}
View
26 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/GroupChat.java
@@ -18,47 +18,39 @@
package com.guntherdw.bukkit.tweakcraft.Chat.Modes;
+import com.guntherdw.bukkit.tweakcraft.Chat.ChatHandler;
import com.guntherdw.bukkit.tweakcraft.Chat.ChatMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
+import java.util.Set;
/**
* @author GuntherDW
*/
-public class GroupChat implements ChatMode {
+public class GroupChat extends ChatMode {
+
+ public GroupChat(ChatHandler instance) {
+ super(instance);
+ }
+
public boolean sendMessage(CommandSender sender, String message) {
return false;
}
- public List<Player> getRecipients(CommandSender sender) {
+ public Set<Player> getRecipients(CommandSender sender) {
return null;
}
- public void addRecipient(String player) {
-
- }
-
public boolean broadcastMessage(CommandSender sender, String message) {
return false;
}
- public void removeRecipient(String player) {
-
- }
-
- public List<String> getSubscribers() {
- return null;
- }
-
public String getDescription() {
return null;
}
- public boolean isEnabled() {
- return false;
- }
public String getColor() {
return null;
View
59 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/LocalChat.java
@@ -27,44 +27,42 @@
import org.bukkit.entity.Player;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* @author GuntherDW
*/
-public class LocalChat implements ChatMode {
+public class LocalChat extends ChatMode {
- private List<String> subscribers;
private TweakcraftUtils plugin;
- private ChatHandler chathandler;
public LocalChat(ChatHandler instance) {
- subscribers = new ArrayList<String>();
- this.chathandler = instance;
- this.plugin = chathandler.getTCUtilsInstance();
+ super(instance);
+ this.plugin = instance.getTCUtilsInstance();
+ this.chatModeName = "L";
}
+ @Override
public boolean sendMessage(CommandSender sender, String message) {
- if (sender instanceof Player) {
- Player player = (Player) sender;
- List<Player> recp = getRecipients(player);
- for (Player p : recp) {
- p.sendMessage(ChatColor.YELLOW + "L" + ChatColor.WHITE + ": [" + player.getDisplayName() + "]: " + message);
- }
- if (recp.size() < 2) {
- sender.sendMessage(ChatColor.GOLD + "No one can hear you!");
- }
- plugin.getLogger().info("L: <" + player.getName() + "> " + message);
- } else {
- sender.sendMessage("How did you get here?!");
+
+ if(!(sender instanceof Player)) {
+ sender.sendMessage(ChatColor.YELLOW+"What were you trying to do?");
+ return true;
}
+
+ super.sendMessage(sender, message);
+ if (getRecipients(sender).size() < 2)
+ sender.sendMessage(ChatColor.GOLD + "No one can hear you!");
+
return true;
}
public boolean broadcastMessage(CommandSender sender, String message) {
if (sender instanceof Player) {
Player player = (Player) sender;
- List<Player> recp = getRecipients(player);
+ Set<Player> recp = getRecipients(player);
for (Player p : recp) {
p.sendMessage(message);
}
@@ -78,8 +76,8 @@ public boolean broadcastMessage(CommandSender sender, String message) {
return true;
}
- public List<Player> getRecipients(CommandSender sender) {
- List<Player> recp = new ArrayList<Player>();
+ public Set<Player> getRecipients(CommandSender sender) {
+ Set<Player> recp = new HashSet<Player>();
if (sender instanceof Player) {
Player player = (Player) sender;
EntityLocation entityloc = new EntityLocation(player);
@@ -95,26 +93,11 @@ public boolean broadcastMessage(CommandSender sender, String message) {
return recp;
}
- public void addRecipient(String player) {
- if (!subscribers.contains(player)) {
- subscribers.add(player);
- }
- }
-
- public void removeRecipient(String player) {
- if (subscribers.contains(player)) {
- subscribers.remove(player);
- }
- }
-
- public List<String> getSubscribers() {
- return subscribers;
- }
-
public String getDescription() {
return "Chat locally (" + plugin.getConfigHandler().localchatdistance + " blocks)";
}
+ @Override
public boolean isEnabled() {
return plugin.getConfigHandler().enableLocalChat && plugin.getConfigHandler().localchatdistance > 0;
}
@@ -124,6 +107,6 @@ public String getColor() {
}
public String getPrefix() {
- return this.getColor() + "L";
+ return this.getColor() + "L"+ChatColor.WHITE;
}
}
View
39 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/RegionChat.java
@@ -31,29 +31,25 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
/**
* @author GuntherDW
*/
-public class RegionChat implements ChatMode {
+public class RegionChat extends ChatMode {
- private List<String> subscribers;
private TweakcraftUtils plugin;
- private ChatHandler chathandler;
public RegionChat(ChatHandler instance) {
- this.chathandler = instance;
+ super(instance);
this.plugin = chathandler.getTCUtilsInstance();
- this.subscribers = new ArrayList<String>();
}
+ @Override
public boolean sendMessage(CommandSender sender, String message) {
if (sender instanceof Player) {
Player player = (Player) sender;
- List<Player> recp = getRecipients(player);
+ Set<Player> recp = getRecipients(player);
for (Player p : recp) {
p.sendMessage(ChatColor.AQUA + "R" + ChatColor.WHITE + ": [" + player.getDisplayName() + "]: " + message);
}
@@ -69,8 +65,8 @@ public boolean sendMessage(CommandSender sender, String message) {
return true;
}
- public List<Player> getRecipients(CommandSender sender) {
- List<Player> recp = new ArrayList<Player>();
+ public Set<Player> getRecipients(CommandSender sender) {
+ Set<Player> recp = new HashSet<Player>();
List<String> regionIds = null;
if (sender instanceof Player) {
GlobalRegionManager gm = plugin.getWorldGuard().getGlobalRegionManager();
@@ -110,7 +106,7 @@ public boolean sendMessage(CommandSender sender, String message) {
public boolean broadcastMessage(CommandSender sender, String message) {
if (sender instanceof Player) {
Player player = (Player) sender;
- List<Player> recp = getRecipients(player);
+ Set<Player> recp = getRecipients(player);
for (Player p : recp) {
p.sendMessage(message);
}
@@ -124,22 +120,6 @@ public boolean broadcastMessage(CommandSender sender, String message) {
return true;
}
- public void addRecipient(String player) {
- if (!subscribers.contains(player)) {
- subscribers.add(player);
- }
- }
-
- public void removeRecipient(String player) {
- if (subscribers.contains(player)) {
- subscribers.remove(player);
- }
- }
-
- public List<String> getSubscribers() {
- return subscribers;
- }
-
public String getDescription() {
return "WorldGuard regions chat!";
}
@@ -168,6 +148,7 @@ public String getRegionName(String sender, boolean color) {
}
}
+ @Override
public boolean isEnabled() {
return plugin.getConfigHandler().enableWorldGuard;
}
@@ -177,6 +158,6 @@ public String getColor() {
}
public String getPrefix() {
- return this.getColor() + "R";
+ return this.getColor() + "R" + ChatColor.WHITE;
}
}
View
66 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/WorldChat.java
@@ -26,45 +26,39 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
/**
* @author GuntherDW
*/
-public class WorldChat implements ChatMode {
+public class WorldChat extends ChatMode {
- private List<String> subscribers;
private TweakcraftUtils plugin;
- private ChatHandler chathandler;
public WorldChat(ChatHandler instance) {
- subscribers = new ArrayList<String>();
- this.chathandler = instance;
- this.plugin = chathandler.getTCUtilsInstance();
+ super(instance);
+ this.plugin = instance.getTCUtilsInstance();
}
+ @Override
public boolean sendMessage(CommandSender sender, String message) {
- if (sender instanceof Player) {
- Player player = (Player) sender;
- List<Player> recp = getRecipients(player);
- for (Player p : recp) {
- p.sendMessage(ChatColor.DARK_GREEN + "W" + ChatColor.WHITE + ": [" + player.getDisplayName() + "]: " + message);
- }
- if (recp.size() < 2) {
- sender.sendMessage(ChatColor.GOLD + "No one can hear you!");
- }
- plugin.getLogger().info("W: (" + player.getWorld().getName() + ") <" + player.getName() + "> " + message);
- } else {
- sender.sendMessage("How did you get here?!");
+
+ if(!(sender instanceof Player)) {
+ sender.sendMessage(ChatColor.YELLOW+"What were you trying to do?");
+ return true;
}
+
+ super.sendMessage(sender, message);
+ if(getRecipients(sender).size() < 2)
+ sender.sendMessage(ChatColor.GOLD + "No one can hear you!");
+
return true;
}
public boolean broadcastMessage(CommandSender sender, String message) {
if (sender instanceof Player) {
Player player = (Player) sender;
- List<Player> recp = getRecipients(player);
+ Set<Player> recp = getRecipients(player);
for (Player p : recp) {
p.sendMessage(message);
}
@@ -78,8 +72,8 @@ public boolean broadcastMessage(CommandSender sender, String message) {
return true;
}
- public List<Player> getRecipients(CommandSender sender) {
- List<Player> recp = new ArrayList<Player>();
+ public Set<Player> getRecipients(CommandSender sender) {
+ Set<Player> recp = new HashSet<Player>();
if (sender instanceof Player) {
Player player = (Player) sender;
EntityLocation entityloc = new EntityLocation(player);
@@ -92,26 +86,11 @@ public boolean broadcastMessage(CommandSender sender, String message) {
return recp;
}
- public void addRecipient(String player) {
- if (!subscribers.contains(player)) {
- subscribers.add(player);
- }
- }
-
- public void removeRecipient(String player) {
- if (subscribers.contains(player)) {
- subscribers.remove(player);
- }
- }
-
- public List<String> getSubscribers() {
- return subscribers;
- }
-
public String getDescription() {
return "World Chat (chat in your current world)";
}
+ @Override
public boolean isEnabled() {
return plugin.getConfigHandler().enableWorldChat;
}
@@ -121,7 +100,14 @@ public String getColor() {
}
public String getPrefix() {
- return this.getColor() + "W";
+ return this.getColor() + "W" + ChatColor.WHITE;
+ }
+
+ @Override
+ public void logChat(CommandSender sender, String message) {
+ /* Nothing but players here, so safe to cast */
+ Player player = (Player) sender;
+ plugin.getLogger().info("W: (" + player.getWorld().getName() + ") <" + player.getName() + "> " + message);
}
}
View
49 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/ZoneChat.java
@@ -27,27 +27,28 @@
import org.bukkit.entity.Player;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* @author GuntherDW
*/
-public class ZoneChat implements ChatMode {
+public class ZoneChat extends ChatMode {
- private List<String> subscribers;
private TweakcraftUtils plugin;
- private ChatHandler chathandler;
public ZoneChat(ChatHandler instance) {
- this.chathandler = instance;
+ super(instance);
this.plugin = chathandler.getTCUtilsInstance();
- this.subscribers = new ArrayList<String>();
}
+
+ @Override
public boolean sendMessage(CommandSender sender, String message) {
if (sender instanceof Player) {
Player player = (Player) sender;
- List<Player> recp = getRecipients(player);
+ Set<Player> recp = getRecipients(player);
for (Player p : recp) {
p.sendMessage(ChatColor.DARK_PURPLE + "Z" + ChatColor.WHITE + ": [" + player.getDisplayName() + "]: " + message);
}
@@ -56,15 +57,15 @@ public boolean sendMessage(CommandSender sender, String message) {
} else if (recp.size() < 2) {
sender.sendMessage(ChatColor.GOLD + "No one can hear you!");
}
- plugin.getLogger().info("Z: (" + getZoneName(player, false) + ") <" + player.getName() + "> " + message);
+
} else {
- sender.sendMessage("How did you get here?!");
+ sender.sendMessage(ChatColor.YELLOW+"What were you trying to do?");
}
return true;
}
- public List<Player> getRecipients(CommandSender sender) {
- List<Player> recp = new ArrayList<Player>();
+ public Set<Player> getRecipients(CommandSender sender) {
+ Set<Player> recp = new HashSet<Player>();
if (sender instanceof Player) {
Player player = (Player) sender;
@@ -89,7 +90,7 @@ public boolean sendMessage(CommandSender sender, String message) {
public boolean broadcastMessage(CommandSender sender, String message) {
if (sender instanceof Player) {
Player player = (Player) sender;
- List<Player> recp = getRecipients(player);
+ Set<Player> recp = getRecipients(player);
for (Player p : recp) {
p.sendMessage(message);
}
@@ -103,22 +104,6 @@ public boolean broadcastMessage(CommandSender sender, String message) {
return true;
}
- public void addRecipient(String player) {
- if (!subscribers.contains(player)) {
- subscribers.add(player);
- }
- }
-
- public void removeRecipient(String player) {
- if (subscribers.contains(player)) {
- subscribers.remove(player);
- }
- }
-
- public List<String> getSubscribers() {
- return subscribers;
- }
-
public String getDescription() {
return "Zones zone chat!";
}
@@ -138,6 +123,7 @@ public String getZoneName(CommandSender sender, boolean color) {
}
}
+ @Override
public boolean isEnabled() {
return plugin.getConfigHandler().enableZones;
}
@@ -147,6 +133,13 @@ public String getColor() {
}
public String getPrefix() {
- return this.getColor() + "Z";
+ return this.getColor() + "Z" + ChatColor.WHITE;
+ }
+
+ @Override
+ public void logChat(CommandSender sender, String message) {
+ /* Nothing but players here, so safe to cast */
+ Player player = (Player) sender;
+ plugin.getLogger().info("Z: (" + getZoneName(player, false) + ") <" + player.getName() + "> " + message);
}
}
View
8 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/AdminCommands.java
@@ -36,7 +36,9 @@
import org.bukkit.entity.Player;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* @author GuntherDW
@@ -98,7 +100,7 @@ public boolean admin_add(CommandSender sender, String command, String[] args, Tw
try {
ChatMode cm = plugin.getChathandler().getChatMode("admin");
- List<String> playernames = new ArrayList<String>();
+ Set<String> playernames = new HashSet<String>();
for (Player p : plugin.getServer().getOnlinePlayers()) {
playernames.add(p.getName());
}
@@ -615,7 +617,7 @@ public boolean tweakcraft(CommandSender sender, String command, String[] args, T
} else if(args[0].equalsIgnoreCase("improvchat")) {
if(sender instanceof Player) {
Player player = (Player) sender;
- List<Player> lijst = plugin.getCUIPlayers();
+ Set<Player> lijst = plugin.getCUIPlayers();
if(lijst!=null && !lijst.contains(player)) {
plugin.getLogger().info("[TweakcraftUtils] Adding "+player.getName()+" to the CUI list!");
lijst.add(player);
@@ -626,7 +628,7 @@ public boolean tweakcraft(CommandSender sender, String command, String[] args, T
} else if(args[0].equalsIgnoreCase("tooldura")) {
if(sender instanceof Player) {
Player player = (Player) sender;
- List<Player> lijst = plugin.getMod_InfDuraplayers();
+ Set<Player> lijst = plugin.getMod_InfDuraplayers();
if(lijst!=null && !lijst.contains(player)) {
plugin.getLogger().info("[TweakcraftUtils] Adding "+player.getName()+" to the mod_InfDura list!");
lijst.add(player);
View
570 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/ChatCommands.java
@@ -21,15 +21,16 @@
import com.guntherdw.bukkit.tweakcraft.Chat.ChatHandler;
import com.guntherdw.bukkit.tweakcraft.Chat.ChatMode;
import com.guntherdw.bukkit.tweakcraft.Chat.Modes.AdminChat;
-import com.guntherdw.bukkit.tweakcraft.Chat.Modes.RegionChat;
-import com.guntherdw.bukkit.tweakcraft.Chat.Modes.ZoneChat;
import com.guntherdw.bukkit.tweakcraft.Commands.aCommand;
import com.guntherdw.bukkit.tweakcraft.Exceptions.*;
+import com.guntherdw.bukkit.tweakcraft.Packages.LocalPlayer;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -38,151 +39,175 @@
public class ChatCommands {
@aCommand(
- aliases = { "chatmode", "cm" },
+ aliases = {"chatmode", "cm"},
permissionBase = "chat",
description = "ChatMode control",
section = "chat"
)
public boolean chatmode(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
- if(sender instanceof Player) {
- if(args.length==0) {
- throw new CommandUsageException("/"+command+" <list|[chatmode]|...>");
- }
- Player player = (Player) sender;
- ChatHandler ch = plugin.getChathandler();
- if(!ch.canTalk(player.getName())) {
- throw new CommandException("You can't use this while muted!");
- }
- String chatMode = args[0].toLowerCase();
- String msg = "";
- if(args.length == 1)
- {
- if(chatMode.equalsIgnoreCase("listplayers") && plugin.check(player, "chat.list")) {
- sender.sendMessage(ChatColor.GOLD + "Current list of players in a chatmode");
- // TODO: better integration
- for(String cms : plugin.getChathandler().listChatModes()) {
-
- try {
- if(plugin.getChathandler().getChatMode(cms).isEnabled()) {
- for(String pla : plugin.getChathandler().getChatMode(cms).getSubscribers()) {
- String color = "";
- try {
- color = plugin.getPlayerColor(pla, true);
- } catch (NullPointerException e) {
- color = ChatColor.WHITE.toString();
- }
- msg = color+pla+ChatColor.WHITE+" ("+plugin.getChathandler().getChatMode(cms).getColor()+cms+ChatColor.WHITE+")";
- sender.sendMessage(msg);
- }
- }
- } catch(ChatModeException ex) {
+ if (args.length == 0) {
+ throw new CommandUsageException("/" + command + " <list|[chatmode]|...>");
+ }
+ return this.chatCommand(sender, command, null, args, plugin);
+ }
- }
- }
- } else if(chatMode.equalsIgnoreCase("list")) {
- msg = ChatColor.GOLD+"Currently enabled chatmodes";
- sender.sendMessage(msg);
- for(String cms : plugin.getChathandler().listChatModes()) {
- try
- {
- if(plugin.getChathandler().getChatMode(cms).isEnabled()) {
- msg = "- "+ChatColor.GOLD+cms+ChatColor.WHITE+" : "+plugin.getChathandler().getChatMode(cms).getDescription();
+
+ public boolean chatCommand(CommandSender sender, String command, String chatModeName, String[] realargs, TweakcraftUtils plugin)
+ throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
+
+ ChatHandler ch = plugin.getChathandler();
+ if (sender instanceof Player && !ch.canTalk(((Player) sender).getName())) {
+ throw new CommandException("You can't use this while muted!");
+ }
+
+ String chatMode = null;
+
+ List<String> args = new ArrayList<String>();
+
+ if (chatModeName != null) {
+ chatMode = chatModeName;
+ args.add(chatModeName);
+ } else {
+ chatMode = realargs[0].toLowerCase();
+ }
+ args = Arrays.asList(realargs);
+
+ String msg = "";
+ if (args.size() == 1) {
+ if (chatMode.equalsIgnoreCase("listplayers")) {
+ if (sender instanceof Player && !plugin.check((Player) sender, "chat.list"))
+ throw new PermissionsException(command);
+
+ sender.sendMessage(ChatColor.GOLD + "Current list of players in a chatmode");
+ // TODO: better integration
+ for (String cms : plugin.getChathandler().listChatModes()) {
+
+ try {
+ if (plugin.getChathandler().getChatMode(cms).isEnabled()) {
+ for (String pla : plugin.getChathandler().getChatMode(cms).getSubscribers()) {
+ String color = "";
+ try {
+ color = plugin.getPlayerColor(pla, true);
+ } catch (NullPointerException e) {
+ color = ChatColor.WHITE.toString();
+ }
+ msg = color + pla + ChatColor.WHITE + " (" + plugin.getChathandler().getChatMode(cms).getColor() + cms + ChatColor.WHITE + ")";
sender.sendMessage(msg);
}
- } catch (ChatModeException ex) {
-
}
+ } catch (ChatModeException ex) {
+
}
- msg = "- "+ChatColor.GOLD+"global"+ChatColor.WHITE+" : Chat globally, remove chatmode subscription";
- sender.sendMessage(msg);
- } else if(chatMode.equalsIgnoreCase("global")) {
- msg = ChatColor.YELLOW+"You will now chat globally!";
+ }
+ } else if (chatMode.equalsIgnoreCase("list")) {
+ msg = ChatColor.GOLD + "Currently enabled chatmodes";
+ sender.sendMessage(msg);
+ for (String cms : plugin.getChathandler().listChatModes()) {
try {
- ChatMode oldcm = ch.getPlayerChatMode(player);
- if(oldcm != null)
- oldcm.removeRecipient(player.getName());
- ch.setPlayerchatmode(player.getName(), null);
- } catch(ChatModeException ex) {
- sender.sendMessage("Can't find chatmode, this shouldn't happen!");
+ if (plugin.getChathandler().getChatMode(cms).isEnabled()) {
+ msg = "- " + ChatColor.GOLD + cms + ChatColor.WHITE + " : " + plugin.getChathandler().getChatMode(cms).getDescription();
+ sender.sendMessage(msg);
+ }
+ } catch (ChatModeException ex) {
+
}
- sender.sendMessage(msg);
- } else { // Join specified chatmode
- try {
+ }
+ msg = "- " + ChatColor.GOLD + "global" + ChatColor.WHITE + " : Chat globally, remove chatmode subscription";
+ sender.sendMessage(msg);
+ } else if (chatMode.equalsIgnoreCase("global") && sender instanceof Player) {
+
+ Player player = (Player) sender;
+ msg = ChatColor.YELLOW + "You will now chat globally!";
+ try {
+ ChatMode oldcm = ch.getPlayerChatMode(player);
+ if (oldcm != null)
+ oldcm.removeRecipient(player.getName());
+ ch.setPlayerchatmode(player.getName(), null);
+ } catch (ChatModeException ex) {
+ sender.sendMessage("Can't find chatmode, this shouldn't happen!");
+ }
+ sender.sendMessage(msg);
+
+ } else { // Join specified chatmode
+ if (sender instanceof Player) {
+ try {
+ Player player = (Player) sender;
+ LocalPlayer lp = plugin.wrapPlayer(player);
ChatMode cm = ch.getChatMode(chatMode);
- if((chatMode.equals("admin") && ((AdminChat)cm).isPlayerAllowed(player.getName()))
- || plugin.check(player, "chat.mode."+chatMode)) {
+ if ((chatMode.equals("admin") && ((AdminChat) cm).isPlayerAllowed(player.getName()))
+ || plugin.check(lp.getBukkitPlayer(), "chat.mode." + chatMode)) {
- if(cm.isEnabled()) {
+ if (cm.isEnabled()) {
ChatMode oldcm = ch.getPlayerChatMode(player);
- if(oldcm != null)
+ if (oldcm != null)
oldcm.removeRecipient(player.getName());
ch.setPlayerchatmode(player.getName(), chatMode);
cm.addRecipient(player.getName());
+ lp.setChatMode(cm);
+
} else {
- throw new CommandException(ChatColor.GOLD+"That ChatMode is not enabled");
+ throw new CommandException(ChatColor.GOLD + "That ChatMode is not enabled");
}
- }
- else
+ } else
throw new PermissionsException("You don't have the permission to join this chatmode!");
- sender.sendMessage(ChatColor.GOLD+"Selected ChatMode : "+chatMode);
- } catch(ChatModeException ex) {
+ sender.sendMessage(ChatColor.GOLD + "Selected ChatMode : " + chatMode);
+ } catch (ChatModeException ex) {
sender.sendMessage("Can't find chatmode!");
}
- }
- } else if(args.length>1) { //Spam the selected chatmode!
- if(chatMode.equals("global")) {
- String spam = "";
- int x = 0;
- for (String m : args) {
- if(x!=0)
- spam += m + " ";
- x++;
- }
- plugin.getServer().broadcastMessage(ChatColor.WHITE+"<"+player.getDisplayName()+ChatColor.WHITE +"> " +spam);
} else {
- try {
- ChatMode cm = ch.getChatMode(chatMode);
-
- if((chatMode.equals("admin") && ((AdminChat)cm).isPlayerAllowed(player.getName()))
- || plugin.check(player, "chat.mode."+chatMode)) {
- if(cm.isEnabled())
- {
- String spam;
- spam = "";
-
- int x = 0;
- for (String m : args) {
- if(x!=0)
- spam += m + " ";
- x++;
- }
- spam = spam.substring(0, spam.length() - 1);
- cm.sendMessage(player, spam);
- } else {
- throw new CommandException(ChatColor.GOLD+"That ChatMode is not enabled");
- }
- } else {
- throw new PermissionsException("You don't have the permission to join this chatmode!");
+ throw new CommandSenderException("What were you trying to do?");
+ }
+ }
+ } else if (args.size() > 1) { //Spam the selected chatmode!
+ if (chatMode.equals("global")) {
+ String spam = "";
+ int x = 0;
+ for (String m : args) {
+ if (x != 0)
+ spam += m + " ";
+ x++;
+ }
+ plugin.getServer().broadcastMessage(ChatColor.WHITE + "<" + (sender instanceof Player ? ((Player) sender).getDisplayName() : ChatColor.LIGHT_PURPLE + "CONSOLE") + ChatColor.WHITE + "> " + spam);
+ } else {
+ try {
+ ChatMode cm = ch.getChatMode(chatMode);
+
+ if (sender instanceof Player)
+ if ((cm instanceof AdminChat ? ((AdminChat) cm).isPlayerAllowed(((Player) sender).getName()) : !plugin.check((Player) sender, "chat.mode." + chatMode)))
+ throw new PermissionsException(command);
+
+ if (cm.isEnabled()) {
+ String spam;
+ spam = "";
+
+ int x = 0;
+ for (String m : args) {
+ if (x != 0)
+ spam += m + " ";
+ x++;
}
-
- } catch(ChatModeException ex) {
- sender.sendMessage("Can't find chatmode!");
+ spam = spam.substring(0, spam.length() - 1);
+ cm.sendMessage(sender, spam);
+ } else {
+ throw new CommandException(ChatColor.GOLD + "That ChatMode is not enabled");
}
+
+ } catch (ChatModeException ex) {
+ sender.sendMessage("Can't find chatmode!");
}
}
- } else {
- throw new CommandSenderException("What are you doing here?");
}
+
return true;
}
@aCommand(
- aliases = { "lc" },
+ aliases = {"lc"},
permissionBase = "chat.mode.local",
description = "Toggle local chat",
section = "chat"
@@ -190,89 +215,17 @@ public boolean chatmode(CommandSender sender, String command, String[] args, Twe
public boolean localchat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
- if(!plugin.getConfigHandler().enableLocalChat) {
+ if (!plugin.getConfigHandler().enableLocalChat) {
throw new CommandUsageException("LocalChat not enabled!");
}
- if (args.length != 0 && args[0].equalsIgnoreCase("list")) {
-
- if (sender instanceof Player)
- if (!plugin.check((Player) sender, "chat.list.local"))
- throw new PermissionsException(command);
-
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("local");
- List<String> sublist = cm.getSubscribers();
- if (sublist.size() != 0) {
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current localchat playerlist:");
- String color = "";
- String msg = "";
- for (String playername : cm.getSubscribers()) {
- try {
- color = plugin.getPlayerColor(playername, true);
- } catch (NullPointerException e) {
- color = ChatColor.WHITE.toString();
- }
- msg = color + playername;
- sender.sendMessage(msg);
- }
- } else {
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current localchat playerlist is empty!");
- }
- // sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current localchat chatters : ");
-
- } catch (ChatModeException e) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- } else if(args.length != 0) {
- if (sender instanceof Player)
- if (!plugin.check((Player) sender, "chat.mode.local"))
- throw new PermissionsException(command);
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("local");
- String msg = "";
- for (String m : args)
- msg += m + " ";
- msg = msg.substring(0, msg.length() - 1);
- cm.sendMessage(sender, msg);
-
- } catch(ChatModeException ex) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- } else {
- if (sender instanceof Player) {
- if (!plugin.check((Player) sender, "chat.mode.local"))
- throw new PermissionsException(command);
-
- else {
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("local");
- List<String> sublist = cm.getSubscribers();
- if (!sublist.contains(((Player) sender).getName())) {
- cm.addRecipient(((Player) sender).getName());
- plugin.getChathandler().setPlayerchatmode(((Player) sender).getName(), "local");
- sender.sendMessage(ChatColor.YELLOW + "You will now chat locally!");
- } else {
- cm.removeRecipient(((Player) sender).getName());
- plugin.getChathandler().setPlayerchatmode(((Player) sender).getName(), null);
- sender.sendMessage(ChatColor.YELLOW + "You will now chat globally!");
- }
-
- } catch (ChatModeException e) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- }
- } else {
- // It's the console!
- throw new CommandSenderException("You need to be a player to use LocalChat!");
- }
- }
+ this.chatCommand(sender, command, "local", args, plugin);
return true;
}
@aCommand(
- aliases = { "rc" },
+ aliases = {"rc"},
permissionBase = "chat.mode.region",
description = "Toggle region chat",
section = "chat"
@@ -280,97 +233,17 @@ public boolean localchat(CommandSender sender, String command, String[] args, Tw
public boolean regionchat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
- if(!plugin.getConfigHandler().enableWorldGuard) {
+ if (!plugin.getConfigHandler().enableWorldGuard) {
throw new CommandUsageException("WorldGuard not enabled!");
}
- if (args.length != 0 && args[0].equalsIgnoreCase("list")) {
-
- if (sender instanceof Player)
- if (!plugin.check((Player) sender, "chat.list.region"))
- throw new PermissionsException(command);
-
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("region");
- List<String> sublist = cm.getSubscribers();
- if (sublist.size() != 0) {
- RegionChat rc = (RegionChat) cm;
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current regionchat playerlist:");
- String color = "";
- String msg = "";
- for (String playername : rc.getSubscribers()) {
- try {
- color = plugin.getPlayerColor(playername, true);
- } catch (NullPointerException e) {
- color = ChatColor.WHITE.toString();
- }
- msg = color + playername + ChatColor.WHITE+" ("+rc.getRegionName(playername, true)+")";
- sender.sendMessage(msg);
- }
- } else {
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current regionchat playerlist is empty!");
- }
- // sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current localchat chatters : ");
-
- } catch (ChatModeException e) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- } else if(args.length != 0) {
- if (sender instanceof Player)
- if (!plugin.check((Player) sender, "chat.mode.region"))
- throw new PermissionsException(command);
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("region");
- String msg = "";
- for (String m : args)
- msg += m + " ";
- msg = msg.substring(0, msg.length() - 1);
- cm.sendMessage(sender, msg);
-
- } catch(ChatModeException ex) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- } else {
- if (sender instanceof Player) {
- if (!plugin.check((Player) sender, "chat.mode.region"))
- throw new PermissionsException(command);
-
- else {
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("region");
- List<String> sublist = cm.getSubscribers();
- if (!sublist.contains(((Player) sender).getName())) {
- RegionChat rc = (RegionChat) cm;
- cm.addRecipient(((Player) sender).getName());
- plugin.getChathandler().setPlayerchatmode(((Player) sender).getName(), "region");
- String rgnames = rc.getRegionName(((Player)sender).getName(), true);
- if(rgnames == null || rc.getRegionName(((Player)sender).getName(), false).equals(""))
- {
- sender.sendMessage(ChatColor.YELLOW + "Regionchat enabled but haven't found any active region!");
- } else {
- sender.sendMessage(ChatColor.YELLOW + "Regionchat in regions "+ChatColor.WHITE+"["+rgnames+"]!");
- }
- } else {
- cm.removeRecipient(((Player) sender).getName());
- plugin.getChathandler().setPlayerchatmode(((Player) sender).getName(), null);
- sender.sendMessage(ChatColor.YELLOW + "You will now chat globally!");
- }
-
- } catch (ChatModeException e) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- }
- } else {
- // It's the console!
- throw new CommandSenderException("You need to be a player to use RegionChat!");
- }
- }
+ this.chatCommand(sender, command, "region", args, plugin);
return true;
}
@aCommand(
- aliases = { "wc" },
+ aliases = {"wc"},
permissionBase = "chat.mode.world",
description = "Toggle world chat",
section = "chat"
@@ -378,183 +251,30 @@ public boolean regionchat(CommandSender sender, String command, String[] args, T
public boolean worldchat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
- if(!plugin.getConfigHandler().enableWorldChat) {
+ if (!plugin.getConfigHandler().enableWorldChat) {
throw new CommandUsageException("WorldChat not enabled!");
}
- if (args.length != 0 && args[0].equalsIgnoreCase("list")) {
-
- if (sender instanceof Player)
- if (!plugin.check((Player) sender, "chat.list.world"))
- throw new PermissionsException(command);
-
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("world");
- List<String> sublist = cm.getSubscribers();
- if (sublist.size() != 0) {
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current WorldChat playerlist:");
- String color = "";
- String msg = "";
- for (String playername : cm.getSubscribers()) {
- try {
- color = plugin.getPlayerColor(playername, true);
- } catch (NullPointerException e) {
- color = ChatColor.WHITE.toString();
- }
- msg = color + playername;
- sender.sendMessage(msg);
- }
- } else {
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current WorldChat playerlist is empty!");
- }
- // sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current localchat chatters : ");
-
- } catch (ChatModeException e) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- } else if(args.length != 0) {
- if (sender instanceof Player)
- if (!plugin.check((Player) sender, "chat.mode.world"))
- throw new PermissionsException(command);
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("world");
- String msg = "";
- for (String m : args)
- msg += m + " ";
- msg = msg.substring(0, msg.length() - 1);
- cm.sendMessage(sender, msg);
-
- } catch(ChatModeException ex) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- } else {
- if (sender instanceof Player) {
- if (!plugin.check((Player) sender, "chat.mode.world"))
- throw new PermissionsException(command);
-
- else {
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("world");
- List<String> sublist = cm.getSubscribers();
- if (!sublist.contains(((Player) sender).getName())) {
- cm.addRecipient(((Player) sender).getName());
- plugin.getChathandler().setPlayerchatmode(((Player) sender).getName(), "world");
- sender.sendMessage(ChatColor.YELLOW + "You will now chat in the current world!");
- } else {
- cm.removeRecipient(((Player) sender).getName());
- plugin.getChathandler().setPlayerchatmode(((Player) sender).getName(), null);
- sender.sendMessage(ChatColor.YELLOW + "You will now chat globally!");
- }
-
- } catch (ChatModeException e) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- }
- } else {
- // It's the console!
- throw new CommandSenderException("You need to be a player to use WorldChat!");
- }
- }
+ this.chatCommand(sender, command, "world", args, plugin);
return true;
}
@aCommand(
- aliases = { "zc" },
+ aliases = {"zc"},
permissionBase = "chat.mode.zone",
description = "Toggle Zone chat",
section = "chat"
)
public boolean executeCommand(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
- if(plugin.getConfigHandler().enableZones==false) {
+ if (plugin.getConfigHandler().enableZones == false) {
throw new CommandUsageException("Zones not enabled!");
}
- if (args.length != 0 && args[0].equalsIgnoreCase("list")) {
-
- if (sender instanceof Player)
- if (!plugin.check((Player) sender, "chat.list.zones"))
- throw new PermissionsException(command);
-
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("zones");
- List<String> sublist = cm.getSubscribers();
- if (sublist.size() != 0) {
- ZoneChat zc = (ZoneChat) cm;
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current ZoneChat playerlist:");
- String color = "";
- String msg = "";
- for (String playername : zc.getSubscribers()) {
- try {
- Player p = plugin.getServer().getPlayer(playername);
- color = plugin.getPlayerColor(playername, true);
- msg = color + playername + ChatColor.WHITE+" ("+zc.getZoneName(p, true)+")";
- sender.sendMessage(msg);
- } catch (NullPointerException e) {
- // color = ChatColor.WHITE.toString();
- }
-
- }
- } else {
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current ZoneChat playerlist is empty!");
- }
- // sender.sendMessage(ChatColor.LIGHT_PURPLE + "Current localchat chatters : ");
-
- } catch (ChatModeException e) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- } else if(args.length != 0) {
- if (sender instanceof Player)
- if (!plugin.check((Player) sender, "chat.mode.zones"))
- throw new PermissionsException(command);
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("zones");
- String msg = "";
- for (String m : args)
- msg += m + " ";
- msg = msg.substring(0, msg.length() - 1);
- cm.sendMessage(sender, msg);
-
- } catch(ChatModeException ex) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- } else {
- if (sender instanceof Player) {
- if (!plugin.check((Player) sender, "chat.mode.zones"))
- throw new PermissionsException(command);
-
- else {
- try {
- ChatMode cm = plugin.getChathandler().getChatMode("zones");
- List<String> sublist = cm.getSubscribers();
- if (!sublist.contains(((Player) sender).getName())) {
- ZoneChat zc = (ZoneChat) cm;
- cm.addRecipient(((Player) sender).getName());
- plugin.getChathandler().setPlayerchatmode(((Player) sender).getName(), "zones");
- String rgnames = zc.getZoneName(sender, true);
- if(rgnames == null || zc.getZoneName(sender, false).equals(""))
- {
- sender.sendMessage(ChatColor.YELLOW + "ZoneChat enabled but haven't found any active zone!");
- } else {
- sender.sendMessage(ChatColor.YELLOW + "ZoneChat in zones "+ChatColor.WHITE+"["+rgnames+"]!");
- }
- } else {
- cm.removeRecipient(((Player) sender).getName());
- plugin.getChathandler().setPlayerchatmode(((Player) sender).getName(), null);
- sender.sendMessage(ChatColor.YELLOW + "You will now chat globally!");
- }
+ this.chatCommand(sender, command, "zones", args, plugin);
- } catch (ChatModeException e) {
- throw new CommandException("Exception thrown when setting chatmode!");
- }
- }
- } else {
- // It's the console!
- throw new CommandSenderException("You need to be a player to use ZoneChat!");
- }
- }
return true;
}
}
View
56 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/EssentialsCommands.java
@@ -43,6 +43,7 @@
import org.bukkit.plugin.PluginDescriptionFile;
import java.io.File;
+import java.lang.reflect.Method;
import java.util.*;
/**
@@ -262,32 +263,34 @@ public boolean help(CommandSender sender, String command, String[] args, Tweakcr
} */
String toadd = "";
for(String cname : commh.getCommandMap().keySet()) {
- try {
- iCommand c = commh.getCommand(cname);
-
- if(addCommandToList(sender, c, plugin)) {
- /* toadd = String.format(ChatColor.GOLD+"%1$-10s"+ChatColor.WHITE+" : "
- +ChatColor.YELLOW+"%2$s", cname, plugin.getCommand(cname).getDescription()); */
- // Fuck minecraft's font :<
- toadd = ChatColor.GOLD+cname+ChatColor.WHITE+
- " : "+ChatColor.YELLOW+plugin.getCommand(cname).getDescription();
- if(aliases) {
- List<String> aliaseslist = plugin.getCommand(cname).getAliases();
- if(aliaseslist.size()>0) {
- toadd += ChatColor.WHITE+" (";
- for(String alias : aliaseslist) {
- toadd+= ChatColor.GOLD+alias+ChatColor.WHITE+",";
- }
- toadd = toadd.substring(0, toadd.length()-1);
- toadd+=")";
+ //try {
+ // iCommand c = commh.getCommand(cname);
+ Method commandMethod = commh.getCommandMap().get(cname);
+ aCommand annotation = commandMethod.getAnnotation(aCommand.class);
+
+ if(addCommandToList(sender, commandMethod, plugin)) {
+ /* toadd = String.format(ChatColor.GOLD+"%1$-10s"+ChatColor.WHITE+" : "
+ +ChatColor.YELLOW+"%2$s", cname, plugin.getCommand(cname).getDescription()); */
+ // Fuck minecraft's font :<
+ toadd = ChatColor.GOLD+cname+ChatColor.WHITE+
+ " : "+ChatColor.YELLOW+plugin.getCommand(cname).getDescription();
+ if(aliases) {
+ List<String> aliaseslist = plugin.getCommand(cname).getAliases();
+ if(aliaseslist.size()>0) {
+ toadd += ChatColor.WHITE+" (";
+ for(String alias : aliaseslist) {
+ toadd+= ChatColor.GOLD+alias+ChatColor.WHITE+",";
}
-
+ toadd = toadd.substring(0, toadd.length()-1);
+ toadd+=")";
}
- cma.add(toadd);
+
}
- } catch (CommandNotFoundException e) {
- throw new CommandException("Exception thrown while calling /help, contact GuntherDW!");
+ cma.add(toadd);
}
+ /* } catch (CommandNotFoundException e) {
+ throw new CommandException("Exception thrown while calling /help, contact GuntherDW!");
+ } */
}
/**
* Extra plugins
@@ -352,12 +355,13 @@ public boolean help(CommandSender sender, String command, String[] args, Tweakcr
return true;
}
- protected boolean addCommandToList(CommandSender sender, iCommand command, TweakcraftUtils plugin) {
+ protected boolean addCommandToList(CommandSender sender, Method command, TweakcraftUtils plugin) {
if(sender instanceof Player) {
- if(command.getPermissionSuffix() == null) {
+ aCommand annotation = command.getAnnotation(aCommand.class);
+ if(annotation == null) {
return true;
} else {
- return plugin.check((Player)sender, command.getPermissionSuffix());
+ return plugin.check((Player)sender, annotation.permissionBase());
}
} else {
return true;
@@ -1266,7 +1270,7 @@ public int compare(Player p1, Player p2) {
// }
msg += toadd;
}
- if (!msg.trim().isEmpty()) {
+ if (!msg.trim().equals("")) {
sender.sendMessage(msg.substring(0, msg.length() - 2));
}
View
3  src/com/guntherdw/bukkit/tweakcraft/Configuration/ConfigurationHandler.java
@@ -93,6 +93,7 @@
public boolean enableTweakTravel = false;
public boolean enableSnowPile = false;
public int snowPileRate = 2;
+ public int snowPileMaxHeight = 7;
public boolean enableSnowDouble = false;
public int tweakTravelSearchWidth = 3;
@@ -235,6 +236,8 @@ public void reloadConfig() {
this.enableFallDistanceNullify = globalconfig.getBoolean("extra.nullifyTeleportFallDistance", false);
this.enableSnowPile = globalconfig.getBoolean("extra.snowpile.enabled", false);
this.snowPileRate = globalconfig.getInt("extra.snowpile.rate", 2500);
+ this.snowPileMaxHeight = globalconfig.getInt("extra.snowpile.maxHeight", 7);
+ this.snowPileMaxHeight = Math.max(this.snowPileMaxHeight, 7);
this.enableSnowDouble = globalconfig.getBoolean("extra.snowpile.doublesnowball", false);
View
2  src/com/guntherdw/bukkit/tweakcraft/DataSources/PersistenceClass/ChatChannel.java
@@ -19,7 +19,7 @@
package com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass;
import com.avaje.ebean.validation.Length;
-import com.sun.istack.internal.NotNull;
+import com.avaje.ebean.validation.NotNull;
import javax.persistence.Entity;
import javax.persistence.Id;
View
2  src/com/guntherdw/bukkit/tweakcraft/DataSources/PersistenceClass/PlayerHistoryInfo.java
@@ -19,7 +19,7 @@
package com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass;
import com.avaje.ebean.validation.Length;
-import com.sun.istack.internal.NotNull;
+import com.avaje.ebean.validation.NotNull;
import javax.persistence.*;
import java.util.Date;
View
2  src/com/guntherdw/bukkit/tweakcraft/DataSources/PersistenceClass/PlayerOptions.java
@@ -19,7 +19,7 @@
package com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass;
import com.avaje.ebean.validation.Length;
-import com.sun.istack.internal.NotNull;
+import com.avaje.ebean.validation.NotNull;
import javax.persistence.Entity;
import javax.persistence.Id;
View
21 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftBlockListener.java
@@ -28,7 +28,6 @@
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.inventory.ItemStack;
-import org.bukkit.material.MaterialData;
import java.util.Random;
@@ -44,26 +43,26 @@ public TweakcraftBlockListener(TweakcraftUtils instance) {
}
public void onSignChange(SignChangeEvent event) {
- if(event.isCancelled()) return;
- if(plugin.getConfigHandler().enableTweakTravel&&event.getLine(0).equalsIgnoreCase("[TweakTravel]") && !plugin.check(event.getPlayer(), "tweaktravel.create")) {
- event.getPlayer().sendMessage(ChatColor.RED+"You don't have permission to create TweakTravel signs!");
+ if (event.isCancelled()) return;
+ if (plugin.getConfigHandler().enableTweakTravel && event.getLine(0).equalsIgnoreCase("[TweakTravel]") && !plugin.check(event.getPlayer(), "tweaktravel.create")) {
+ event.getPlayer().sendMessage(ChatColor.RED + "You don't have permission to create TweakTravel signs!");
event.setCancelled(true);
}
}
public void onBlockForm(BlockFormEvent event) {
- if(event.isCancelled()) return;
- if(!plugin.getConfigHandler().enableSnowPile) return;
+ if (event.isCancelled()) return;
+ if (!plugin.getConfigHandler().enableSnowPile) return;
Block b = event.getBlock();
BlockState bnewstate = event.getNewState();
BlockState boldstate = b.getState();
int rate = plugin.getConfigHandler().snowPileRate;
- if(boldstate.getTypeId() == 78) {
+ if (boldstate.getTypeId() == 78) {
Random rnd = new Random();
byte snowstate = boldstate.getData().getData();
- if(snowstate<7 && (rnd.nextInt(Integer.MAX_VALUE)%rate*25)==0) {
+ if (snowstate < (plugin.getConfigHandler().snowPileMaxHeight + 1) && (rnd.nextInt(Integer.MAX_VALUE) % rate * 25) == 0) {
snowstate += 1;
bnewstate.setData(Material.SNOW.getNewData(snowstate));
} else {
@@ -75,12 +74,12 @@ public void onBlockForm(BlockFormEvent event) {
public void onBlockBreak(BlockBreakEvent event) {
- if(event.isCancelled()) return;
- if(!plugin.getConfigHandler().enableSnowDouble) return;
+ if (event.isCancelled()) return;
+ if (!plugin.getConfigHandler().enableSnowDouble) return;
Block block = event.getBlock();
- if(block.getTypeId() == 78&&block.getData()>3)
+ if (block.getTypeId() == 78 && block.getData() > 2)
block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.SNOW_BALL, 1));
}
View
505 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java
@@ -51,54 +51,54 @@
//private final Logger log = Logger.getLogger("Minecraft");
private final TweakcraftUtils plugin;
- private List<String> invisplayers;
+ private Set<String> invisplayers;
private Map<String, String> nicks;
- private List<PlayerInfo> playerinfo = new ArrayList<PlayerInfo>();
- private List<PlayerOptions> playeroptions = new ArrayList<PlayerOptions>();
- private List<String> nomount = new ArrayList<String>();
+ private Set<PlayerInfo> playerinfo = new HashSet<PlayerInfo>();
+ private Set<PlayerOptions> playeroptions = new HashSet<PlayerOptions>();
+ private Set<String> nomount = new HashSet<String>();
- public List<String> getNomount() {
+ public Set<String> getNomount() {
return nomount;
}
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
- if(event.isCancelled()) return;
- if(!plugin.getConfigHandler().extraLogging) return;
+ if (event.isCancelled()) return;
+ if (!plugin.getConfigHandler().extraLogging) return;
String line = event.getMessage();
String cmd = event.getMessage();
- if(line.contains(" ")) {
+ if (line.contains(" ")) {
String c[] = cmd.split(" ");
cmd = c[0];
}
- if(cmd.startsWith("/") && cmd.length()>1)
+ if (cmd.startsWith("/") && cmd.length() > 1)
cmd = cmd.substring(1);
boolean go = true;
PluginCommand pcmd = this.plugin.getCommand(cmd);
- if(pcmd!=null && plugin.getCommandHandler().getCommandMap().containsKey(pcmd.getName()))
- go=false;
+ if (pcmd != null && plugin.getCommandHandler().getCommandMap().containsKey(pcmd.getName()))
+ go = false;
- if(go) {
- plugin.getLogger().info("[TweakLog] "+event.getPlayer().getName()+" issued: "+line);
+ if (go) {
+ plugin.getLogger().info("[TweakLog] " + event.getPlayer().getName() + " issued: " + line);
}
}
public void removeNoMountPersistence(String playername) {
- if(plugin.getConfigHandler().enablePersistence) {
+ if (plugin.getConfigHandler().enablePersistence) {
List<PlayerOptions> po = plugin.getDatabase().find(PlayerOptions.class).where().ieq("name", playername).ieq("optionname", "nomount").findList();
- if(po == null || po.isEmpty())
+ if (po == null || po.isEmpty())
return;
plugin.getDatabase().delete(po);
}
}
public void addNoMountPersistence(String playername) {
- if(plugin.getConfigHandler().enablePersistence) {
+ if (plugin.getConfigHandler().enablePersistence) {
// PlayerOptions po = new PlayerOptions();
List<PlayerOptions> popts = plugin.getDatabase().find(PlayerOptions.class).where().ieq("name", playername).ieq("optionname", "nomount").findList();
- if(popts != null && !popts.isEmpty())
+ if (popts != null && !popts.isEmpty())
removeNoMountPersistence(playername);
// popts = new ArrayList<PlayerOptions>();
@@ -111,7 +111,7 @@ public void addNoMountPersistence(String playername) {
public TweakcraftPlayerListener(TweakcraftUtils instance) {
plugin = instance;
- invisplayers = new ArrayList<String>();
+ invisplayers = new HashSet<String>();
nicks = new HashMap<String, String>();
}
@@ -119,9 +119,9 @@ public void setNick(String player, String nick) {
nicks.put(player, nick);
LocalPlayer lp = plugin.wrapPlayer(player);
lp.setNick(nick);
- if(plugin.getConfigHandler().enablePersistence) {
+ if (plugin.getConfigHandler().enablePersistence) {
PlayerInfo pi = plugin.getDatabase().find(PlayerInfo.class).where().ieq("name", player).findUnique();
- if(pi==null) {
+ if (pi == null) {
pi = new PlayerInfo();
pi.setName(player);
}
@@ -133,47 +133,53 @@ public void setNick(String player, String nick) {
public boolean removeNick(String player) {
LocalPlayer lp = plugin.wrapPlayer(player);
- if(lp.hasNick()) {
+ if (lp.hasNick()) {
nicks.remove(player);
- if(plugin.getConfigHandler().enablePersistence) {
+ if (plugin.getConfigHandler().enablePersistence) {
PlayerInfo pi = plugin.getDatabase().find(PlayerInfo.class).where().ieq("name", player).findUnique();
- if(pi==null) {
+ if (pi == null) {
pi = new PlayerInfo();
pi.setName(player);
}
- pi.setNick((String)null);
+ pi.setNick((String) null);
lp.setNick(null);
plugin.getDatabase().update(pi);
}
return true;
- } else { return false; }
+ } else {
+ return false;
+ }
}
public String getNick(String player) {
- if(nicks.containsKey(player)) {
+ if (nicks.containsKey(player)) {
return nicks.get(player);
} else {
return null;
}
}
- public Player findPlayerByNick(String nick) { return findPlayerByNick(nick, false); }
+ public Player findPlayerByNick(String nick) {
+ return findPlayerByNick(nick, false);
+ }
- public String findPlayerNameByNick(String nick) { return findPlayerNameByNick(nick, false); }
+ public String findPlayerNameByNick(String nick) {
+ return findPlayerNameByNick(nick, false);
+ }
public Player findPlayerByNick(String nick, boolean exact) {
String p = null;
String n = null;
- for(String part : nicks.keySet()) {
+ for (String part : nicks.keySet()) {
n = nicks.get(part);
- if(exact ? n.toLowerCase().equals(nick.toLowerCase()) : n.toLowerCase().contains(nick.toLowerCase())) {
+ if (exact ? n.toLowerCase().equals(nick.toLowerCase()) : n.toLowerCase().contains(nick.toLowerCase())) {
p = part;
}
}
- if(p!=null) {
+ if (p != null) {
return plugin.getServer().getPlayer(p);
}
return null;
@@ -183,11 +189,11 @@ public Player findPlayerByNick(String nick, boolean exact) {
String n = null;
List<Player> playerlijst = new ArrayList<Player>();
- for(String part : nicks.keySet()) {
+ for (String part : nicks.keySet()) {
n = nicks.get(part);
- if(n.toLowerCase().contains(nick.toLowerCase())) {
+ if (n.toLowerCase().contains(nick.toLowerCase())) {
Player player = plugin.getServer().getPlayerExact(part);
- if(player!=null) playerlijst.add(player);
+ if (player != null) playerlijst.add(player);
}
}
return playerlijst;
@@ -198,11 +204,11 @@ public String findPlayerNameByNick(String nick, boolean strict) {
String p = null;
String n = null;
- for(String part : nicks.keySet()) {
+ for (String part : nicks.keySet()) {
n = nicks.get(part);
- if(strict? n.toLowerCase().equals(nick.toLowerCase()) : n.toLowerCase().contains(nick.toLowerCase())) {
+ if (strict ? n.toLowerCase().equals(nick.toLowerCase()) : n.toLowerCase().contains(nick.toLowerCase())) {
p = part;
- if(strict) return p;
+ if (strict) return p;
}
}
@@ -214,8 +220,8 @@ public boolean nickTaken(String nick) {
}
public boolean nickTakenCheck(String playername, String nick) {
- if(nicks.values().contains(nick)) {
- if(getNick(playername).equals(nick))
+ if (nicks.values().contains(nick)) {
+ if (getNick(playername).equals(nick))
return false;
else
return true;
@@ -224,11 +230,10 @@ public boolean nickTakenCheck(String playername, String nick) {
}
public boolean nickTakenPersistance(String playername, String nick) {
- if(plugin.getConfigHandler().enablePersistence) {
+ if (plugin.getConfigHandler().enablePersistence) {
PlayerInfo pi = plugin.getDatabase().find(PlayerInfo.class).where().ieq("nick", nick).findUnique();
- if(pi!=null)
- {
- if(!pi.getName().equals(playername)) {
+ if (pi != null) {
+ if (!pi.getName().equals(playername)) {
return true;
}
}
@@ -236,37 +241,37 @@ public boolean nickTakenPersistance(String playername, String nick) {
return false;
}
- public List<String> getInvisplayers() {
+ public Set<String> getInvisplayers() {
return invisplayers;
}
public void reloadInfo() {
- playerinfo = plugin.getDatabase().find(PlayerInfo.class).findList();
+ playerinfo = plugin.getDatabase().find(PlayerInfo.class).findSet();
nicks.clear();
- for(PlayerInfo pi : playerinfo) {
+ for (PlayerInfo pi : playerinfo) {
LocalPlayer lp = plugin.wrapPlayer(pi.getName());
- if(pi.getNick()!=null) {
- if(plugin.getConfigHandler().enableDebug)
- plugin.getLogger().info("[TweakcraftUtils] Setting "+pi.getName()+"'s nick to "+pi.getNick());
+ if (pi.getNick() != null) {
+ if (plugin.getConfigHandler().enableDebug)
+ plugin.getLogger().info("[TweakcraftUtils] Setting " + pi.getName() + "'s nick to " + pi.getNick());
nicks.put(pi.getName(), pi.getNick());
pi.setNick(pi.getNick());
}
}
- playeroptions = plugin.getDatabase().find(PlayerOptions.class).findList();
+ playeroptions = plugin.getDatabase().find(PlayerOptions.class).findSet();
nomount.clear();
- for(PlayerOptions po : playeroptions) {
- if(po.getOptionname().equals("nomount")) {
- if(plugin.getConfigHandler().enableDebug)
- plugin.getLogger().info("[TweakcraftUtils] Setting "+po.getName()+"'s no-ride option!");
+ for (PlayerOptions po : playeroptions) {
+ if (po.getOptionname().equals("nomount")) {
+ if (plugin.getConfigHandler().enableDebug)
+ plugin.getLogger().info("[TweakcraftUtils] Setting " + po.getName() + "'s no-ride option!");
nomount.add(po.getName());
}
- if(po.getOptionname().equals("mute")) {
- if(plugin.getConfigHandler().enableDebug)
- plugin.getLogger().info("[TweakcraftUtils] Setting "+po.getName()+"'s mute option!");
+ if (po.getOptionname().equals("mute")) {
+ if (plugin.getConfigHandler().enableDebug)
+ plugin.getLogger().info("[TweakcraftUtils] Setting " + po.getName() + "'s mute option!");
Long toTime = null;
- try{
- if(po.getOptionvalue()!=null) {
+ try {
+ if (po.getOptionvalue() != null) {
toTime = Long.parseLong(po.getOptionvalue());
}
} catch (NumberFormatException ex) {
@@ -278,16 +283,20 @@ public void reloadInfo() {
}
public void onPlayerChat(PlayerChatEvent event) {
- if(event.isCancelled()) return;
+ if (event.isCancelled()) return;
Player player = event.getPlayer();
String message = event.getMessage();
String name = player.getName();
String displayName = plugin.getNickWithColors(player.getName());
- String ldisplayname = displayName.substring(0, displayName.length()-2);
+ String ldisplayname = displayName.substring(0, displayName.length() - 2);
player.setDisplayName(displayName);
- if(ldisplayname.length()<=16)
- try{ player.setPlayerListName(ldisplayname); } catch(IllegalArgumentException ex) { ; }
+ if (ldisplayname.length() <= 16)
+ try {
+ player.setPlayerListName(ldisplayname);
+ } catch (IllegalArgumentException ex) {
+ ;
+ }
ChatHandler ch = plugin.getChathandler();
ChatMode cm = ch.getPlayerChatMode(player);
@@ -299,23 +308,23 @@ public void onPlayerChat(PlayerChatEvent event) {
return;
}
- if(plugin.getConfigHandler().enableSpamControl) {
+ if (plugin.getConfigHandler().enableSpamControl) {
int counter = 0;
counter = ch.getAntiSpam().checkSpam(player, message);
- if(counter>(plugin.getConfigHandler().spamMaxMessages-1)) {
- plugin.getLogger().info("[TweakcraftUtils] "+player.getName()+" has been auto-muted for spamming!");
- long until = plugin.getConfigHandler().spamMuteMinutes*60;
+ if (counter > (plugin.getConfigHandler().spamMaxMessages - 1)) {
+ plugin.getLogger().info("[TweakcraftUtils] " + player.getName() + " has been auto-muted for spamming!");
+ long until = plugin.getConfigHandler().spamMuteMinutes *