Permalink
Browse files

More refactoring,

Added a test for the newer Event format,
Fixed some typo's,
Added AgeLock tamermode,
Added ClientBridge support (will put that on GitHub shortly, after i iron out some horrible code)
  • Loading branch information...
1 parent 81a1e5d commit f37610de9596ec01fb1d57b14b2dac0a1ae3f9ba @GuntherDW committed Feb 10, 2012
Showing with 354 additions and 269 deletions.
  1. +2 −2 plugin.yml
  2. +3 −5 src/com/guntherdw/bukkit/tweakcraft/Chat/ChatHandler.java
  3. +30 −0 src/com/guntherdw/bukkit/tweakcraft/Chat/ChatMode.java
  4. +2 −1 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java
  5. +0 −134 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/TCUtilsChat.java
  6. +9 −0 src/com/guntherdw/bukkit/tweakcraft/Commands/CommandHandler.java
  7. +1 −1 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/AdminCommands.java
  8. +1 −1 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/ChatCommands.java
  9. +1 −1 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/DebugCommands.java
  10. +11 −3 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/EssentialsCommands.java
  11. +9 −1 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/GeneralCommands.java
  12. +4 −2 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/TeleportationCommands.java
  13. +2 −2 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/WeatherCommands.java
  14. +32 −20 src/com/guntherdw/bukkit/tweakcraft/Configuration/ConfigurationHandler.java
  15. +7 −3 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftBlockListener.java
  16. +9 −1 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftEntityListener.java
  17. +94 −15 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java
  18. +7 −4 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftWorldListener.java
  19. +2 −2 src/com/guntherdw/bukkit/tweakcraft/Packages/CraftIRCEndPoint.java
  20. +9 −0 src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java
  21. +1 −0 src/com/guntherdw/bukkit/tweakcraft/Packages/TamerMode.java
  22. +2 −2 src/com/guntherdw/bukkit/tweakcraft/Tools/ArgumentParser.java
  23. +14 −17 src/com/guntherdw/bukkit/tweakcraft/Tools/PermissionsResolver.java
  24. +11 −0 src/com/guntherdw/bukkit/tweakcraft/Tools/TamerTool.java
  25. +47 −13 src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java
  26. +5 −5 src/com/guntherdw/bukkit/tweakcraft/Util/EntityLocation.java
  27. +39 −34 src/com/guntherdw/bukkit/tweakcraft/Util/TeleportHistory.java
View
@@ -1,7 +1,7 @@
name: TweakcraftUtils
main: com.guntherdw.bukkit.tweakcraft.TweakcraftUtils
-softdepend: [ 'CraftIRC' ]
-#depend: [ CraftIRC ]
+# softdepend: [ 'CraftIRC' ]
+# depend: [ CraftIRC ]
version: 2.8.0-git
authors:
- GuntherDW
@@ -45,8 +45,6 @@ public ChatHandler(TweakcraftUtils instance) {
this.registerChatMode("region", new RegionChat(this));
this.registerChatMode("zones", new ZoneChat(this));
this.registerChatMode("world", new WorldChat(this));
-
- this.registerChatMode("tcutils", new TCUtilsChat(this)); /* IRC extra stuff */
}
public boolean registerChatMode(String chatModeLabel, ChatMode chatMode) {
@@ -82,9 +80,9 @@ public TweakcraftUtils getTCUtilsInstance() {
public List<String> listChatModes() {
List<String> l = new ArrayList<String>();
- for (String s : chatmodes.keySet()) {
- if ((chatmodes.get(s)).isEnabled() && !((chatmodes.get(s)).isHidden()))
- l.add(s);
+ for (Map.Entry<String, ChatMode> s : chatmodes.entrySet()) {
+ if(s.getValue().isEnabled() && !s.getValue().isHidden())
+ l.add(s.getKey());
}
return l;
}
@@ -60,6 +60,22 @@ public boolean sendMessage(CommandSender sender, String message) {
return true;
}
+ /**
+ * Broadcasts a message in the ChatMode without a playertag
+ *
+ * @param message
+ * @return
+ */
+ public boolean broadcastMessage(String message) {
+ // String msg = message;
+ for (Player p : getRecipients(null)) {
+ p.sendMessage(message);
+ }
+
+ logChat(message);
+ return true;
+ }
+
/**
* Returns a list of players that will get the message
*
@@ -155,6 +171,11 @@ public String getLoggingFormatString() {
return name + ": <%1$s> %2$s";
}
+ public String getLoggingFormatStringNoPlayerTag() {
+ String name = this.chatModeName == null ? getClass().getSimpleName() : chatModeName;
+ return name + ": %1$s";
+ }
+
public String getChatFormatString() {
String prefix = getPrefix();
return (prefix != null ? prefix + ": " : "") + "[%1$s] %2$s";
@@ -167,4 +188,13 @@ public void logChat(CommandSender sender, String message) {
logger.info(logMessage);
}
}
+
+ public void logChat(String message) {
+
+ String logFormat = getLoggingFormatString();
+ if (logFormat != null) {
+ String logMessage = String.format(getLoggingFormatStringNoPlayerTag(), message);
+ logger.info(logMessage);
+ }
+ }
}
@@ -110,6 +110,7 @@ public boolean broadcastMessage(CommandSender sender, String message) {
return true;
}
+ @Override
public boolean broadcastMessage(String message) {
// String msg = message;
for (Player p : getRecipients(null)) {
@@ -194,6 +195,6 @@ public String getColor() {
}
public String getPrefix() {
- return this.getColor() + "A";
+ return this.getColor() + "A" + ChatColor.WHITE.toString();
}
}
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2012 GuntherDW
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package com.guntherdw.bukkit.tweakcraft.Chat.Modes;
-
-import com.ensifera.animosity.craftirc.CraftIRC;
-import com.ensifera.animosity.craftirc.EndPoint;
-import com.ensifera.animosity.craftirc.RelayedMessage;
-import com.guntherdw.bukkit.tweakcraft.Chat.ChatHandler;
-import com.guntherdw.bukkit.tweakcraft.Chat.ChatMode;
-import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author GuntherDW
- */
-public class TCUtilsChat extends ChatMode {
-
- private TweakcraftUtils plugin;
- // private EndPoint tcendpoint = null;
- private CraftIRC circ = null;
- private Set<Player> emptyHashSet = new HashSet<Player>();
-
- public TCUtilsChat(ChatHandler instance) {
- super(instance);
- this.plugin = instance.getTCUtilsInstance();
- // this.tcendpoint = plugin.getEndPoint();
- if (plugin.getConfigHandler().enableIRC) {
- this.circ = plugin.getCraftIRC();
- circ.registerEndPoint("tcutils", plugin.getEndPoint());
-
- // this.tcendpoint =
- }
- }
-
- @Override
- public Set<Player> getRecipients(CommandSender sender) {
- return emptyHashSet;
- }
-
- @Override
- public boolean broadcastMessage(CommandSender sender, String message) {
- String msg = message;
- if (sender instanceof Player) {
- sender.sendMessage(msg);
- }
- for (Player p : getRecipients(sender)) {
- p.sendMessage(msg);
- }
- return true;
- }
-
- @Override
- public boolean isEnabled() {
- return true;
- }
-
- @Override
- public boolean sendMessage(CommandSender sender, String message) {
- String sendername = "";
- String pcolor = "";
- String cleanname;
-
- if(plugin.getConfigHandler().enableIRC) {
-
- if (sender instanceof Player) {
- sendername = ((Player) sender).getDisplayName(); // ((Player)sender).getName();
- pcolor = ""; // getDisplayName handles this one!
- cleanname = ((Player) sender).getName();
- } else {
- sendername = "CONSOLE";
- cleanname = sendername;
- pcolor = ChatColor.LIGHT_PURPLE.toString();
- }
- String targetmsg = plugin.getConfigHandler().GIRCMessageFormat;
- targetmsg = targetmsg.replace("%name%", cleanname).
- replace("%message%", message).
- replace("%dispname%", ChatColor.stripColor(sendername));
- RelayedMessage rmsg = plugin.getCraftIRC().newMsgToTag(plugin.getAdminEndPoint(), plugin.getConfigHandler().GIRCtag, "generic");
- rmsg.setField("sender", pcolor + sendername);
- rmsg.setField("realSender", cleanname);
- rmsg.setField("message", targetmsg);
- if (sender instanceof Player) {
- Player p = (Player) sender;
- // World w = p.getWorld();
- rmsg.setField("world", p.getWorld().getName());
- rmsg.setField("prefix", plugin.getPermissions().getResolver().getUserPrefix(p.getWorld().getName(), p));
- rmsg.setField("suffix", plugin.getPermissions().getResolver().getUserSuffix(p.getWorld().getName(), p));
- }
- rmsg.post();
- }
- return true;
- }
-
- @Override
- public boolean isHidden() {
- return true;
- }
-
- @Override
- public String getDescription() {
- return "CraftIRC extra endpoint";
- }
-
- @Override
- public String getColor() {
- return ChatColor.WHITE.toString();
- }
-
- @Override
- public String getPrefix() {
- return "TCIRC";
- }
-}
@@ -186,6 +186,11 @@ public boolean executeCommand(CommandSender sender, String name, String[] args)
public boolean runMethod(CommandSender sender, String name, String[] args)
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
+ String argsString = "";
+ for(String a : args) {
+ argsString+= a+" ";
+ }
+
try {
Method command = getCommand(name);
return (Boolean) command.invoke(getMethodInstance(command), sender, name, args);
@@ -201,9 +206,13 @@ public boolean runMethod(CommandSender sender, String name, String[] args)
throw (CommandException) t;
logger.warning("[TweakcraftUtils] Error occured while executing command!");
+ logger.warning("[TweakcraftUtils] Errornous command : "+name+" "+argsString+"!");
+ logger.warning("[TweakcraftUtils] CommandSender : "+(sender instanceof Player?((Player)sender).getName():"CONSOLE"));
e.printStackTrace();
} catch (IllegalAccessException e) {
logger.warning("[TweakcraftUtils] Error occured while executing command!");
+ logger.warning("[TweakcraftUtils] Errornous command : "+name+" "+argsString+"!");
+ logger.warning("[TweakcraftUtils] CommandSender : "+(sender instanceof Player?((Player)sender).getName():"CONSOLE"));
e.printStackTrace();
}
@@ -45,7 +45,7 @@
*/
public class AdminCommands {
- TweakcraftUtils plugin;
+ private TweakcraftUtils plugin;
public AdminCommands(TweakcraftUtils instance) {
this.plugin = instance;
@@ -38,7 +38,7 @@
*/
public class ChatCommands {
- TweakcraftUtils plugin;
+ private TweakcraftUtils plugin;
public ChatCommands(TweakcraftUtils instance) {
this.plugin = instance;
@@ -34,7 +34,7 @@
*/
public class DebugCommands {
- TweakcraftUtils plugin;
+ private TweakcraftUtils plugin;
public DebugCommands(TweakcraftUtils instance) {
this.plugin = instance;
@@ -53,8 +53,7 @@
*/
public class EssentialsCommands {
-
- TweakcraftUtils plugin;
+ private TweakcraftUtils plugin;
public EssentialsCommands(TweakcraftUtils instance) {
this.plugin = instance;
@@ -987,6 +986,7 @@ public boolean spawnMob(CommandSender sender, String command, String[] realargs)
int health = ap.getInteger("h", -1);
boolean powered = ap.getBoolean("pow", false);
boolean shoven = ap.getBoolean("sh", false);
+ boolean agelock = ap.getBoolean("l", false);
String sheepcolor = ap.getString("sc", null);
String victim = ap.getString("p", null);
int age = ap.getInteger("a", -1);
@@ -1066,6 +1066,7 @@ public boolean spawnMob(CommandSender sender, String command, String[] realargs)
if (sender instanceof Player) {
victimplayer = (Player) sender;
loc = victimplayer.getTargetBlock((HashSet<Byte>) null, 200).getLocation();
+ loc.add(0, 1, 0);
} else {
throw new CommandException("If you're a console, at least tell me who i need to scare?");
}
@@ -1078,8 +1079,15 @@ public boolean spawnMob(CommandSender sender, String command, String[] realargs)
if (health > 0)
lent.setHealth(health);
- if (lent instanceof Animals && age != -1)
+ if (lent instanceof Animals && age != -1) {
((Animals) lent).setAge(age);
+ if(ap.isflagUsed("l"))
+ ((Animals) lent).setAgeLock(true);
+ else
+ ((Animals) lent).setAgeLock(agelock);
+
+ }
+
if (lent instanceof Slime && slimesize > 0)
((Slime) lent).setSize(slimesize);
@@ -51,7 +51,7 @@
*/
public class GeneralCommands {
- TweakcraftUtils plugin;
+ private TweakcraftUtils plugin;
public GeneralCommands(TweakcraftUtils instance) {
this.plugin = instance;
@@ -927,6 +927,14 @@ public boolean tamer(CommandSender sender, String command, String[] args)
}
mode = new TamerMode(state, TamerMode.TamerModes.SIT);
player.sendMessage(ChatColor.GREEN+"TamerTool SIT MODE selected!");
+ } else if(args.length>0 && args[0].equalsIgnoreCase("agelock")) {
+ // Boolean ageLock = false;
+ if(args.length>1) {
+ state = Boolean.parseBoolean(args[1]);
+ }
+ mode = new TamerMode(state, TamerMode.TamerModes.SETAGELOCK);
+ player.sendMessage(ChatColor.GREEN+"TamerTool AGELOCK MODE selected!");
+
} else if(args.length>0 && args[0].equalsIgnoreCase("setage")) {
int age = -1;
if(args.length>1) {
@@ -40,7 +40,7 @@
*/
public class TeleportationCommands {
- TweakcraftUtils plugin;
+ private TweakcraftUtils plugin;
public TeleportationCommands(TweakcraftUtils instance) {
this.plugin = instance;
@@ -123,7 +123,7 @@ public boolean teleportToLocation(CommandSender sender, String command, String[]
if (args.length == 3) {
if (y == null) y = Integer.parseInt(args[2]);
} else {
- y = 129;
+ y = -1;
}
} catch (NumberFormatException ex) {
throw new CommandException("I need numbers not strings!");
@@ -164,6 +164,8 @@ public boolean teleportToLocation(CommandSender sender, String command, String[]
Location oldloc = victim.getLocation();
Location loc = new Location(world, x.doubleValue(), y.doubleValue(), z.doubleValue());
+ if (y == -1) loc.setY(loc.getWorld().getMaxHeight() + 1);
+
if (victim.teleport(loc)) {
plugin.getTelehistory().addHistory(victim.getName(), oldloc);
}
@@ -42,7 +42,7 @@
*/
public class WeatherCommands {
- TweakcraftUtils plugin;
+ private TweakcraftUtils plugin;
public WeatherCommands(TweakcraftUtils instance) {
this.plugin = instance;
@@ -71,7 +71,7 @@ public boolean strikeLightning(CommandSender sender, String command, String[] ar
throw new CommandUsageException("Can't find player!");
}
loc = players.get(0).getLocation();
- sender.sendMessage(ChatColor.RED + "I hope " + players.get(0).getName() + ChatColor.RED + " wasn't standing under a tree!");
+ sender.sendMessage(ChatColor.RED + "I hope " + players.get(0).getDisplayName() + ChatColor.RED + " wasn't standing under a tree!");
}
if (loc != null) {
Oops, something went wrong.

0 comments on commit f37610d

Please sign in to comment.