Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added per-world MOTD support,

Modified the /ban command to "search" for players by default, use the -e flag if you want an exact match
Moved some more code to LocalPlayer,
Fixed typo in /tphere
Optimised some conditionals
Added a flag type system to the ArgumentParser, it now parses '-flag value' type arguments as well
Added a static getInstance() for plugin developers that do not wish to "register" with Bukkit.
  • Loading branch information...
commit 88bbd9dd8f5e29976f2c2f8d60c9a4d22936c0bd 1 parent f77e052
@GuntherDW authored
Showing with 418 additions and 268 deletions.
  1. +0 −4 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java
  2. +5 −0 src/com/guntherdw/bukkit/tweakcraft/Commands/Admin/CommandTC.java
  3. +30 −8 src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandBan.java
  4. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandItem.java
  5. +7 −6 src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandMsg.java
  6. +12 −11 src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandReply.java
  7. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandSpawnmob.java
  8. +2 −4 src/com/guntherdw/bukkit/tweakcraft/Commands/General/CommandBroadcast.java
  9. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Commands/General/CommandGetSpawn.java
  10. +9 −6 src/com/guntherdw/bukkit/tweakcraft/Commands/Teleportation/CommandTele.java
  11. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Commands/Teleportation/CommandTp.java
  12. +1 −1  src/com/guntherdw/bukkit/tweakcraft/Commands/Teleportation/CommandTphere.java
  13. +7 −21 src/com/guntherdw/bukkit/tweakcraft/Configuration/ConfigurationHandler.java
  14. +2 −5 src/com/guntherdw/bukkit/tweakcraft/DataSources/Ban/BanHandler.java
  15. +8 −16 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftEntityListener.java
  16. +73 −60 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java
  17. +9 −0 src/com/guntherdw/bukkit/tweakcraft/Packages/Argument.java
  18. +8 −12 src/com/guntherdw/bukkit/tweakcraft/Packages/CraftIRCEndPoint.java
  19. +25 −9 src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java
  20. +82 −23 src/com/guntherdw/bukkit/tweakcraft/Tools/ArgumentParser.java
  21. +66 −46 src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java
  22. +15 −11 src/com/guntherdw/bukkit/tweakcraft/Worlds/TweakWorld.java
  23. +50 −21 src/com/guntherdw/bukkit/tweakcraft/Worlds/WorldManager.java
  24. +3 −0  src/com/guntherdw/bukkit/tweakcraft/Worlds/iWorld.java
View
4 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java
@@ -76,10 +76,6 @@ public boolean sendMessage(CommandSender sender, String message) {
targetmsg = targetmsg.replace("%dispname%", ChatColor.stripColor(sendername));
targetmsg = targetmsg.replace("%clearcolors%", Character.toString((char) 3));
-
- // plugin.getCraftIRC().sendMessageToTag(targetmsg, plugin.getConfigHandler().AIRCtag);
- /// plugin.getCraftIRC().newMsgToTag(this, plugin.getConfigHandler().AIRCtag, targetmsg);
-
RelayedMessage rmsg = plugin.getCraftIRC().newMsgToTag(plugin.getAdminEndPoint(), plugin.getConfigHandler().AIRCtag, "generic");
rmsg.setField("sender", pcolor+sendername);
rmsg.setField("realSender", cleanname);
View
5 src/com/guntherdw/bukkit/tweakcraft/Commands/Admin/CommandTC.java
@@ -27,6 +27,7 @@
import com.guntherdw.bukkit.tweakcraft.Packages.ItemDB;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import com.guntherdw.bukkit.tweakcraft.Worlds.TweakWorld;
+import com.guntherdw.bukkit.tweakcraft.Worlds.WorldManager;
import com.guntherdw.bukkit.tweakcraft.Worlds.iWorld;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@@ -72,6 +73,10 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
try{ p.setPlayerListName(ldisplayname); } catch(IllegalArgumentException ex) { ; }
}
}
+ WorldManager wm = plugin.getworldManager();
+ for(String worldname : wm.getWorlds().keySet()) {
+ wm.loadMotd(worldname);
+ }
plugin.getPlayerListener().reloadInvisTable();
/**
* This is handled by the config.reloadConfig() call.
View
38 src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandBan.java
@@ -24,42 +24,64 @@
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandSenderException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandUsageException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.PermissionsException;
+import com.guntherdw.bukkit.tweakcraft.Tools.ArgumentParser;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import com.guntherdw.bukkit.tweakcraft.Util.TimeTool;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.List;
+
/**
* @author GuntherDW
*/
public class CommandBan implements iCommand {
- public boolean executeCommand(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
+ public boolean executeCommand(CommandSender sender, String command, String[] realargs, TweakcraftUtils plugin)
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
if (sender instanceof Player)
if (!plugin.check((Player) sender, "ban"))
throw new PermissionsException(command);
+ List<Player> playerlist = null;
BanHandler handler = plugin.getBanhandler();
+
+ ArgumentParser ap = new ArgumentParser(realargs);
+ boolean exact = ap.isflagUsed("e");
+ String durationarg = ap.getString("t", null);
+ String[] args = ap.getUnusedArgs();
+
if (args.length < 1)
throw new CommandUsageException(ChatColor.YELLOW + "I need at least 1 name to ban!");
- if (handler.isBanned(args[0])) {
+
+ String playername = args[0];
+
+ if(!exact) {
+ sender.sendMessage(ChatColor.LIGHT_PURPLE+"PlayerFinder enabled.");
+ playerlist = plugin.getServer().matchPlayer(playername);
+ if(playerlist.size()==1) {
+ playername = playerlist.get(0).getName();
+ sender.sendMessage(ChatColor.YELLOW+"Found "+playername);
+ } else {
+ throw new CommandException("Didn't find the player, cancelling!");
+ }
+ }
+
+ if (handler.isBanned(playername)) {
sender.sendMessage(ChatColor.YELLOW + "This player is already banned!");
} else {
String reason = "";
- String playername = args[0];
String duration = null;
Long dura = null;
+
String toFull = null;
if (args.length > 1) {
- boolean skipfirst = false;
- if(args[1].startsWith("t:")) {
+ if(durationarg!=null) {
duration = args[1].substring(2);
dura = TimeTool.calcTime(duration);
toFull = TimeTool.getDurationFull(duration);
duration = duration.substring(0, duration.length()-1);
}
- if(dura!=null) skipfirst=true;
- for (int x = skipfirst?2:1; x < args.length; x++) {
+ for (int x = 1; x < args.length; x++) {
reason += args[x] + " ";
}
if (reason.length() > 1)
@@ -72,7 +94,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
handler.banPlayer(playername.toLowerCase(), reason, dura);
sender.sendMessage(ChatColor.YELLOW + "Banning " + playername + ChatColor.YELLOW+ (dura!=null?" for "+duration+" "+toFull+"!":""));
- Player player = plugin.getServer().getPlayer(playername);
+ Player player = plugin.getServer().getPlayerExact(playername);
if (player != null) {
sender.sendMessage(ChatColor.YELLOW + "Kickbanning " + player.getName());
player.kickPlayer(reason);
View
2  src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandItem.java
@@ -57,7 +57,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
ArgumentParser ap = new ArgumentParser(realargs);
String recv = ap.getString("p", null);
int dmgval = ap.getInteger("d", -1);
- String[] args = ap.getNormalArgs();
+ String[] args = ap.getUnusedArgs();
if (args.length > 0) // just the item!
{
View
13 src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandMsg.java
@@ -23,6 +23,7 @@
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandSenderException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandUsageException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.PermissionsException;
+import com.guntherdw.bukkit.tweakcraft.Packages.LocalPlayer;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -50,18 +51,18 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
String message = "";
for (int x = 1; x < args.length; x++) {
- message += args[x] + " ";
- }
- if (message.length() > 1) {
- message = message.substring(0, message.length() - 1);
+ message += args[x] + (x<args.length?" ":"");
}
if (playerto == null)
throw new CommandException("Can't find that player!");
sender.sendMessage("[Me -> " + playerto.getDisplayName() + "] " + message);
playerto.sendMessage("[" + senderName + " -> Me] " + message);
- if (sender instanceof Player)
- plugin.setPlayerReply(playerto.getName(), ((Player) sender).getName());
+ if (sender instanceof Player) {
+ LocalPlayer lp = plugin.wrapPlayer((Player)sender);
+ lp.setReplyTo(playerto.getName());
+ // plugin.setPlayerReply(playerto.getName(), ((Player) sender).getName());
+ }
plugin.getLogger().info("[TweakcraftUtils] (MSG) " + clearName + " -> " + playerto.getName() + " : " + message);
} else if (args.length == 1) {
View
23 src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandReply.java
@@ -23,6 +23,7 @@
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandSenderException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandUsageException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.PermissionsException;
+import com.guntherdw.bukkit.tweakcraft.Packages.LocalPlayer;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -36,26 +37,26 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
if (sender instanceof Player) {
if (args.length > 0) {
Player player = (Player) sender;
- String replyto = plugin.getPlayerReply(((Player) sender).getName());
- // String replyto = player.getName();
-
+ LocalPlayer lp = plugin.wrapPlayer(player);
+ String replyTo = lp.getReplyTo();
String message = "";
+
+ if (replyTo == null)
+ throw new CommandException("Can't find the player to reply to!");
+
for (int x = 0; x < args.length; x++) {
- message += args[x] + " ";
- }
- if (message.length() > 1) {
- message = message.substring(0, message.length() - 1);
+ message += args[x] + (x<args.length?" ":"");
}
- if (replyto == null)
- throw new CommandException("Can't find the player to reply to!");
- Player playerto = plugin.findPlayerasPlayer(replyto);
+ LocalPlayer lpTo = plugin.wrapPlayer(replyTo);
+ Player playerto = lp.getBukkitPlayerSafe();
if (playerto == null)
throw new CommandException("That player is no longer online!");
sender.sendMessage("[Me -> " + playerto.getDisplayName() + "] " + message);
playerto.sendMessage("[" + player.getDisplayName() + " -> Me] " + message);
- plugin.setPlayerReply(playerto.getName(), player.getName());
+ lpTo.setReplyTo(player.getName());
+ // plugin.setPlayerReply(playerto.getName(), player.getName());
plugin.getLogger().info("[TweakcraftUtils] (MSG) " + player.getName() + " -> " + playerto.getName() + " : " + message);
} else if (args.length == 0) {
throw new CommandUsageException("I need a message!");
View
2  src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandSpawnmob.java
@@ -49,7 +49,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
Location loc = player.getTargetBlock((HashSet<Byte>)null, 200).getLocation();
ArgumentParser ap = new ArgumentParser(realargs);
- String[] args = ap.getNormalArgs();
+ String[] args = ap.getUnusedArgs();
Random rnd = new Random();
int slimesize = ap.getInteger("s", -1);
View
6 src/com/guntherdw/bukkit/tweakcraft/Commands/General/CommandBroadcast.java
@@ -67,10 +67,8 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
if (args.length < 1) {
throw new CommandUsageException("You did not specify a message!");
} else {
- for (String m : args) {
- message += m + " ";
- }
- message = message.substring(0, message.length() - 1);
+ for(int x = 0; x < args.length; x++)
+ message += args[x] + (x<args.length?" ":"");
}
View
2  src/com/guntherdw/bukkit/tweakcraft/Commands/General/CommandGetSpawn.java
@@ -43,7 +43,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
ArgumentParser ap = new ArgumentParser(realargs);
String world = ap.getString("w", null);
String player = ap.getString("p", null);
- String[] args = ap.getNormalArgs();
+ String[] args = ap.getUnusedArgs();
String permString = this.getPermissionSuffix();
View
15 src/com/guntherdw/bukkit/tweakcraft/Commands/Teleportation/CommandTele.java
@@ -39,9 +39,12 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
boolean isPlayer = false;
ArgumentParser ap = new ArgumentParser(realargs);
+ Integer x = ap.getInteger("x", null);
+ Integer y = ap.getInteger("y", null);
+ Integer z = ap.getInteger("z", null);
String w = ap.getString("w", null);
String p = ap.getString("p", null);
- String[] args = ap.getNormalArgs();
+ String[] args = ap.getUnusedArgs();
if (sender instanceof Player) {
isPlayer = true;
if (!plugin.check((Player) sender, "tele"))
@@ -52,9 +55,9 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
// Player player = (Player) sender;
- Integer x = null;
+ /* Integer x = null;
Integer y = null;
- Integer z = null;
+ Integer z = null; */
World world = null;
if(args.length == 0) {
@@ -98,10 +101,10 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
}
} else {
try{
- x = Integer.parseInt(args[0]);
- z = Integer.parseInt(args[1]);
+ if (x==null) x = Integer.parseInt(args[0]);
+ if (z==null) z = Integer.parseInt(args[1]);
if (args.length == 3) {
- y = Integer.parseInt(args[2]);
+ if (y==null) y = Integer.parseInt(args[2]);
} else {
y = 129;
}
View
2  src/com/guntherdw/bukkit/tweakcraft/Commands/Teleportation/CommandTp.java
@@ -45,7 +45,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
if(p1==null) p1 = ap.getString("f", null);
String p2 = ap.getString("t", null);
- String[] args = ap.getNormalArgs();
+ String[] args = ap.getUnusedArgs();
if (sender instanceof Player) {
Player player = (Player) sender;
View
2  src/com/guntherdw/bukkit/tweakcraft/Commands/Teleportation/CommandTphere.java
@@ -93,7 +93,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
} else {
player.sendMessage(ChatColor.YELLOW + "Failed to teleport " + pto.getDisplayName() + ChatColor.YELLOW + " to you!");
pto.sendMessage(player.getDisplayName() + ChatColor.YELLOW
- + ChatColor.RED + "tried/failed"+ ChatColor.YELLOW + " to teleport you to him!");
+ + ChatColor.RED + " tried/failed"+ ChatColor.YELLOW + " to teleport you to him!");
}
View
28 src/com/guntherdw/bukkit/tweakcraft/Configuration/ConfigurationHandler.java
@@ -76,6 +76,7 @@
public boolean enablemod_InfDura = false;
public boolean enableExperienceOrbsHalt = false;
public boolean enableTargetIgnoreAFKPlayers = false;
+ public boolean enableWorldMOTD = false;
// public PermissionsResolver.PermissionResolvingMode permissoinsResolvingMode = null;
@@ -135,7 +136,6 @@ public void reloadConfig() {
this.enableRespawnHook = globalconfig.getBoolean("respawn.enableHook", false);
this.enableRespawnHeal = globalconfig.getBoolean("respawn.healOnRespawn", false);
-
this.extrahelpplugin = new ArrayList<String>();
this.enableGroupChat = globalconfig.getBoolean("ChatMode.GroupChat", true);
this.enablePersistence = globalconfig.getBoolean("Persistence.enabled", true);
@@ -159,26 +159,6 @@ public void reloadConfig() {
}
}
this.cancelNetherPortal = globalconfig.getBoolean("worlds.cancelportal", false);
- /* this.enableBukkitPermissions = globalconfig.getBoolean("Permissions.BukkitPerms", false);
- if(this.enableBukkitPermissions)
- plugin.getLogger().warning("[TweakcraftUtils] Enabling Bukkit perms resolving, this is an experimental feature, expect bugs!"); */
- String presolver = globalconfig.getString("Permissions.resolver", null);
- if(presolver==null) presolver = "permissions";
-
- /* This is done fully automatic now! */
- /* if(presolver.equals("permissions")) {
- permissoinsResolvingMode = PermissionsResolver.PermissionResolvingMode.NIJIPERMS;
- } else if(presolver.equals("permissionsex")) {
- permissoinsResolvingMode = PermissionsResolver.PermissionResolvingMode.PERMISSIONSEX;
- } else if(presolver.equals("bukkitperms")) {
- permissoinsResolvingMode = PermissionsResolver.PermissionResolvingMode.BUKKIT;
- }
- plugin.getPermissionsResolver().setMode(permissoinsResolvingMode);
-
- if(permissoinsResolvingMode!= PermissionsResolver.PermissionResolvingMode.NIJIPERMS) {
- plugin.getLogger().warning("[TweakcraftUtils] Other permissions resolver selected than Nijokun's Permissiosn plugin, this is experimental!");
- } */
-
this.extrahelphide = globalconfig.getStringList("extrahelp.hide", null);
if (globalconfig.getBoolean("PlayerHistory.enabled", false)) {
@@ -203,6 +183,8 @@ public void reloadConfig() {
this.cancelNickChat = globalconfig.getBoolean("extra.cancelNickChat", true);
this.extraLogging = globalconfig.getBoolean("extra.extraLogging", false);
+ this.enableWorldMOTD = globalconfig.getBoolean("worlds.worldMOTD", false);
+
this.enableSpamControl = globalconfig.getBoolean("spamcontrol.enable", false);
if(this.enableSpamControl) {
plugin.getLogger().info("[TweakcraftUtils] Enabling spam control!");
@@ -249,4 +231,8 @@ public Configuration getSeenconfig() {
public Map<String, LockdownLocation> getLockdowns() {
return lockdowns;
}
+
+ public String getDirSeperator() {
+ return System.getProperty("file.separator");
+ }
}
View
7 src/com/guntherdw/bukkit/tweakcraft/DataSources/Ban/BanHandler.java
@@ -69,11 +69,8 @@ private void loadBans() {
}
}
banfilereader.close();
- } catch (FileNotFoundException e) {
- plugin.getLogger().info("[TweakcraftUtils] Ban file not found!");
- } catch (IOException e) {
-
- }
+ } catch (FileNotFoundException e) { plugin.getLogger().warning("[TweakcraftUtils] Ban file not found!");
+ } catch (IOException e) { plugin.getLogger().info("[TweakcraftUtils] Ban file I/O error!"); }
if(plugin.getConfigHandler().enablePersistence) {
List<PlayerOptions> popts = plugin.getDatabase(). find(PlayerOptions.class).where().ieq("optionname", "ban").findList();
for(PlayerOptions po : popts) {
View
24 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftEntityListener.java
@@ -40,9 +40,9 @@ public TweakcraftEntityListener(TweakcraftUtils instance) {
}
public void onEntityTarget(EntityTargetEvent event) {
- if(!plugin.getConfigHandler().enableTargetIgnoreAFKPlayers) return;
- if(event.isCancelled()) return;
- if(!(event.getTarget() instanceof Player)) return;
+ if(!plugin.getConfigHandler().enableTargetIgnoreAFKPlayers
+ || event.isCancelled() || !(event.getTarget() instanceof Player)) return;
+
LocalPlayer lp = plugin.wrapPlayer((Player) event.getTarget());
if(event.getReason().equals(EntityTargetEvent.TargetReason.CLOSEST_PLAYER)
|| event.getReason().equals(EntityTargetEvent.TargetReason.RANDOM_TARGET)) {
@@ -56,10 +56,8 @@ public void onEntityCombust(EntityCombustEvent event) {
if(ent instanceof Player) {
Player player = (Player) ent;
- if(plugin.getWorldGuard()!=null) {
- if(plugin.getWorldGuard().getGlobalConfiguration().hasGodMode(player)) {
- event.setCancelled(true);
- }
+ if(plugin.getWorldGuard()!=null&&plugin.getWorldGuard().getGlobalConfiguration().hasGodMode(player)) {
+ event.setCancelled(true);
}
}
}
@@ -79,17 +77,11 @@ public void onEntityDeath(EntityDeathEvent event) {
}
public void onExplosionPrime(ExplosionPrimeEvent event) {
- if(event.isCancelled())
- return;
+ if(event.isCancelled()) return;
Entity ent = event.getEntity();
- if(ent != null)
- {
- if(!ent.isEmpty()) {
- if(ent.getPassenger() instanceof Player) {
- event.setCancelled(true);
- }
- }
+ if(ent != null && !ent.isEmpty() && ent.getPassenger() instanceof Player) {
+ event.setCancelled(true);
}
}
View
133 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java
@@ -28,6 +28,7 @@
import com.guntherdw.bukkit.tweakcraft.Packages.Ban;
import com.guntherdw.bukkit.tweakcraft.Packages.LocalPlayer;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
+import com.guntherdw.bukkit.tweakcraft.Worlds.WorldManager;
import com.guntherdw.bukkit.tweakcraft.Worlds.iWorld;
import org.bukkit.*;
import org.bukkit.command.PluginCommand;
@@ -152,9 +153,9 @@ public String getNick(String player) {
}
public Player findPlayerByNick(String nick) { return findPlayerByNick(nick, false); }
-
+
public String findPlayerNameByNick(String nick) { return findPlayerNameByNick(nick, false); }
-
+
public Player findPlayerByNick(String nick, boolean exact) {
String p = null;
@@ -180,7 +181,7 @@ public Player findPlayerByNick(String nick, boolean exact) {
for(String part : nicks.keySet()) {
n = nicks.get(part);
if(n.toLowerCase().contains(nick.toLowerCase())) {
- Player player = plugin.getServer().getPlayer(part);
+ Player player = plugin.getServer().getPlayerExact(part);
if(player!=null) playerlijst.add(player);
}
}
@@ -291,49 +292,48 @@ public void onPlayerChat(PlayerChatEvent event) {
plugin.getLogger().info("[TweakcraftUtils] Muted player message : <" + event.getPlayer().getName() + "> " + event.getMessage());
event.setCancelled(true);
return;
- } else {
+ }
- 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;
- ch.addMute(player.getName().toLowerCase(), until);
- String msg = plugin.getConfigHandler().spamMuteMessage.trim();
- if(!msg.equals("")) {
-
- msg = msg.replace("{name}", name);
- msg = msg.replace("{displayname}", player.getDisplayName());
- msg = msg.replace("{mins}", plugin.getConfigHandler().spamMuteMinutes+"");
- msg = msg.replace("&&", "{orly}");
- msg = msg.replace("&", "§");
- msg = msg.replace("{orly}", "&");
-
- plugin.getServer().broadcastMessage(msg);
- }
- event.setCancelled(true);
- return;
+ 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;
+ ch.addMute(player.getName().toLowerCase(), until);
+ String msg = plugin.getConfigHandler().spamMuteMessage.trim();
+ if(!msg.equals("")) {
+
+ msg = msg.replace("{name}", name);
+ msg = msg.replace("{displayname}", player.getDisplayName());
+ msg = msg.replace("{mins}", plugin.getConfigHandler().spamMuteMinutes+"");
+ msg = msg.replace("&&", "{orly}");
+ msg = msg.replace("&", "§");
+ msg = msg.replace("{orly}", "&");
+
+ plugin.getServer().broadcastMessage(msg);
}
+ event.setCancelled(true);
+ return;
}
+ }
- if (cm != null) {
- if (!message.startsWith(plugin.getChathandler().getBypassChar())) {
- cm.sendMessage(player, message);
+ if (cm != null) {
+ if (!message.startsWith(plugin.getChathandler().getBypassChar())) {
+ cm.sendMessage(player, message);
+ event.setCancelled(true);
+ } else {
+ message = message.substring(1);
+ event.setMessage(message);
+ if(!(message.length()>0)) {
event.setCancelled(true);
- } else {
- message = message.substring(1);
- event.setMessage(message);
- if(!(message.length()>0)) {
- event.setCancelled(true);
- return;
- }
+ return;
}
- } else if(cm == null && getInvisplayers().contains(event.getPlayer().getName())) {
- event.getPlayer().sendMessage(ChatColor.RED + "Are you insane? You're invisible, set a chatmode!");
- event.setCancelled(true);
}
+ } else if(cm == null && getInvisplayers().contains(event.getPlayer().getName())) {
+ event.getPlayer().sendMessage(ChatColor.RED + "Are you insane? You're invisible, set a chatmode!");
+ event.setCancelled(true);
}
if(!event.isCancelled() && cm==null) {
@@ -346,7 +346,7 @@ public void onPlayerChat(PlayerChatEvent event) {
// plugin.getServer().broadcastMessage(ChatColor.WHITE+"<"+player.getDisplayName()+ChatColor.WHITE+"> "+message);
for(Player p : plugin.getServer().getOnlinePlayers())
p.sendMessage(ChatColor.WHITE + "<" + player.getDisplayName() + ChatColor.WHITE + "> " + message);
- }
+ }
}
}
}
@@ -379,7 +379,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
}
public void onPlayerTeleport(PlayerTeleportEvent event) {
- if(event.isCancelled()) return;
+ if (event.isCancelled()) return;
if (event.getFrom().getWorld() != event.getTo().getWorld()) { // The world is different, make a check!
Player player = event.getPlayer();
if(plugin.getConfigHandler().enablemod_InfDura) {
@@ -388,13 +388,13 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
if (!plugin.check(player, "worlds." + event.getTo().getWorld().getName())) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You don't have access to this world!");
+ return;
}
iWorld tw = plugin.getworldManager().getWorld(event.getTo().getWorld().getName(), true);
if(tw!=null && !tw.getGameMode().equals(player.getGameMode())) {
player.setGameMode(tw.getGameMode());
}
}
- // if(event)
}
@@ -428,24 +428,10 @@ public void onPlayerJoin(PlayerJoinEvent event) {
if(getInvisplayers().contains(event.getPlayer().getName())) { // Invisible players do not send out a "joined" message
event.setJoinMessage(null);
p.sendMessage(ChatColor.AQUA + "You has joined STEALTHILY!");
- /* if (plugin.getCraftIRC() != null) {
- plugin.getCraftIRC().sendMessageToTag("STEALTH JOIN : " +event.getPlayer().getName() ,"mchatadmin");
- } */
- /* try {
- ChatHandler ch = plugin.getChathandler();
- ChatMode cm = ch.getChatMode("admin");
- AdminChat am = (AdminChat) cm; */
for(Player play : plugin.getServer().getOnlinePlayers())
{
- if(plugin.check(play, "tpinvis"))
- {
- play.sendMessage(ChatColor.AQUA+"Stealth join : "+event.getPlayer().getDisplayName());
- }
+ if(plugin.check(play, "tpinvis")) play.sendMessage(ChatColor.AQUA+"Stealth join : "+event.getPlayer().getDisplayName());
}
- // am.broadcastMessageRealAdmins(ChatColor.AQUA+"Stealth join : "+event.getPlayer().getDisplayName());
- /* } catch (ChatModeException e) {
- e.printStackTrace();
- } */
}
if(plugin.getConfigHandler().enableCUI) {
@@ -561,7 +547,8 @@ public void onPlayerInteract(PlayerInteractEvent event) {
if(plugin.getConfigHandler().getLockdowns().containsKey(playername)) {
target = plugin.getConfigHandler().getLockdowns().get(playername).getTarget();
} else {
- Location loc = player.getTargetBlock((HashSet<Byte>)null, 200).getLocation();
+ int maxDistance = player.getServer().getViewDistance()*16;
+ Location loc = player.getTargetBlock((HashSet<Byte>)null, maxDistance).getLocation();
loc.setY(loc.getY()+1);
target = loc.clone();
}
@@ -601,10 +588,24 @@ public void onPlayerKick(PlayerKickEvent event) {
public void reloadInvisTable() {
List<String> lijst = plugin.getConfiguration().getStringList("invisible-playerlist", null);
- this.invisplayers.clear();
+
if(lijst != null)
{
+ /* Clear the old playerlist, there could be old players on there,
+ who have been tagged as visible for now. */
+ for(String s : this.invisplayers) {
+ LocalPlayer lp = plugin.wrapPlayer(s);
+ lp.setInvisible(false);
+ }
+ this.invisplayers.clear();
+
this.invisplayers.addAll(lijst);
+
+ /* Add any old and new players who have been tagged as invisible. */
+ for(String s : lijst) {
+ LocalPlayer lp = plugin.wrapPlayer(s);
+ lp.setInvisible(true);
+ }
}
if(plugin.getConfigHandler().enableDebug)
for(String s : lijst)
@@ -626,7 +627,7 @@ public void onPlayerPortal(PlayerPortalEvent event) {
if(!w.isNetherEnabled()) {
if(plugin.getConfigHandler().cancelNetherPortal) event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED+"This world doesn't have an extra nether!");
-
+
return;
}
@@ -732,4 +733,16 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
}
}
}
+
+ public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
+ if(!plugin.getConfigHandler().enableWorldMOTD) return;
+
+ Player player = event.getPlayer();
+ WorldManager wm = plugin.getworldManager();
+ iWorld world = wm.getWorld(player.getWorld().getName(), true);
+ if(world!=null && world.hasWorldMOTD()) {
+ for(String line : world.getMOTD())
+ player.sendMessage(line);
+ }
+ }
}
View
9 src/com/guntherdw/bukkit/tweakcraft/Packages/Argument.java
@@ -25,6 +25,7 @@
private Integer id;
private String argname;
private Object argvalue;
+ private boolean argType; /* arg:argvalue or Flag */
private boolean _used;
public Argument(Integer position, String argname, Object argvalue) {
@@ -66,4 +67,12 @@ public boolean is_used() {
public void set_used(boolean state) {
this._used = state;
}
+
+ public boolean isArgType() {
+ return argType;
+ }
+
+ public void setArgType(boolean argtype) {
+ this.argType = argtype;
+ }
}
View
20 src/com/guntherdw/bukkit/tweakcraft/Packages/CraftIRCEndPoint.java
@@ -42,24 +42,20 @@ public CraftIRCEndPoint(TweakcraftUtils instance) {
@Override
public Type getType() {
- return EndPoint.Type.IRC;
+ return EndPoint.Type.MINECRAFT;
}
@Override
public void messageIn(RelayedMessage relayedMessage) {
- /* chat: '%grey%[IRC]%foreground% <%ircPrefix%%sender%> %message%'
- private: '%grey%[IRC]%foreground% %sender% whispers> %message%'
- action: '%grey%[IRC]%purple% * %ircPrefix%%sender% %message%'
- join: '%grey%[IRC]%darkgreen% * Joins: %sender%'
- part: '%grey%[IRC]%darkgreen% * Parts: %sender%'
- quit: '%grey%[IRC]%blue% * Quits: %sender%'
- kick: '%grey%[IRC]%darkgreen% * %sender% was kicked by %ircModPrefix%%moderator%'
- nick: '%grey%[IRC]%darkgreen% * %sender% is now known as %message%'
- generic: '%grey%%message%' */
-
/* String event = relayedMessage.getEvent();
if(event.equals("chat") || event.equals("action")) {
-
+ String pname = relayedMessage.getField("sender");
+ if(pname!=null) {
+ String name = relayedMessage.getField("sender");
+ String nick = plugin.getPlayerListener().findPlayerNameByNick(name, true);
+ relayedMessage.setField("sender", plugin.getNickWithColors(nick==null?name:nick));
+ }
+ ac.broadcastMessage(relayedMessage.getMessage(this));
} */
}
View
34 src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java
@@ -32,30 +32,46 @@
private int spamcounter;
private long lastmessagetime;
private String nick=null;
+ private boolean invisible=false;
+ private String replyTo=null;
+
+ public boolean isInvisible() {
+ return this.invisible;
+ }
+
+ public void setInvisible(boolean state) {
+ this.invisible = state;
+ }
-
public boolean hasNick() {
return nick!=null;
}
-
+
public String getNick() {
return this.nick;
}
-
+
+ public String getReplyTo() {
+ return replyTo;
+ }
+
+ public void setReplyTo(String replyTo) {
+ this.replyTo = replyTo;
+ }
+
public void setNick(String nick) {
this.nick = nick;
}
-
- public Player getBukkitPlayerSafe() {
- return bukkitPlayer;
- }
- public Player getBukkitPlayer() {
+ public Player getBukkitPlayerSafe() {
if(this.bukkitPlayer == null) {
Player p = Bukkit.getPlayerExact(player);
if(p!=null) bukkitPlayer=p;
}
-
+ return bukkitPlayer;
+ }
+
+ public Player getBukkitPlayer() {
return bukkitPlayer;
}
View
105 src/com/guntherdw/bukkit/tweakcraft/Tools/ArgumentParser.java
@@ -32,23 +32,35 @@
private Map<String, Argument> _namedargs;
private List<Argument> _args;
+ private List<String> _flagsUsed;
public ArgumentParser(String[] args) {
_namedargs = new HashMap<String, Argument>();
_args = new ArrayList<Argument>();
+ _flagsUsed = new ArrayList<String>();
int x=0;
for(String arg: args) {
-
- String[] argslist = arg.split("\\:", 2);
- // _args.put(argslist)
- if(argslist.length>1) {
- argslist[0] = argslist[0].toLowerCase();
- Argument argument = new Argument(x, argslist[0], argslist[1]);
- _namedargs.put(argslist[0], argument);
- _args.add(argument);
- } else {
- Argument argument = new Argument(x, null, argslist[0]);
+ if(arg.startsWith("-")) { /* Flag type */
+ Argument argument = new Argument(x, arg.substring(1), null);
+ argument.setArgType(true);
+ if(args.length > x+1) { /* Add the value as well! */
+ argument.setArgvalue(args[x+1]);
+ }
+ _namedargs.put(argument.getArgname(), argument);
_args.add(argument);
+ } else { /* Possible argname:argvalue type */
+ String[] argslist = arg.split("\\:", 2);
+ // _args.put(argslist)
+ if(argslist.length>1) {
+ argslist[0] = argslist[0].toLowerCase();
+ Argument argument = new Argument(x, argslist[0], argslist[1]);
+ argument.setArgType(false);
+ _namedargs.put(argslist[0], argument);
+ _args.add(argument);
+ } else {
+ Argument argument = new Argument(x, null, argslist[0]);
+ _args.add(argument);
+ }
}
// arglist
x++;
@@ -56,17 +68,25 @@ public ArgumentParser(String[] args) {
}
public ArgumentParser() { }
-
+
public void setUsed(String argName, boolean state) {
Argument arg = null;
// First the named argument map, this is the easiest one.
arg = _namedargs.get(argName);
- if(arg!=null) arg.set_used(state);
-
+ if(arg!=null) {
+ arg.set_used(state);
+ if(arg.isArgType()) {
+ int pos = arg.getId();
+ if(_args.size()>pos) _args.get(pos+1).set_used(true);
+ }
+ }
// Second the List<Argument> one, this'll require a for loop
for(int x=0; x<_args.size(); x++) {
arg = _args.get(x);
if(arg.getArgname() != null && arg.getArgname().equals(argName)) arg.set_used(state);
+ if(arg.isArgType()) {
+ if(_args.size()>x) _args.get(x+1).set_used(true);
+ }
}
}
@@ -134,10 +154,22 @@ public String getString(String argname, String defaultval) {
return defaultval;
}
+ public boolean is_Flag(Argument arg) {
+ boolean flag = false;
+ int pos = arg.getId();
+ if(pos < _args.size()) {
+ if(arg.isArgType()) flag = true;
+ }
+ if(!flag && pos > 0) {
+ if(_args.get(pos-1).isArgType()) flag = true;
+ }
+ return flag;
+ }
+
public List<Argument> getDefaultArguments() {
List<Argument> vals = new ArrayList<Argument>();
for(Argument arg: _args) {
- if(arg.getArgname()==null)
+ if(!is_Flag(arg) && arg.getArgname() == null)
vals.add(arg);
}
return vals;
@@ -146,32 +178,59 @@ public String getString(String argname, String defaultval) {
public List<Argument> getUnusedArgsList() {
List<Argument> vals = new ArrayList<Argument>();
for(Argument arg : _args) {
- if(arg.getArgname()==null || !arg.is_used())
+ if(is_Flag(arg) && !arg.is_used()) {
+ vals.add(arg);
+ } else if(arg.getArgname()==null || !arg.is_used())
vals.add(arg);
}
return vals;
}
+ public boolean isflagUsed(String needle) { /* Reserved for simple flag checking */
+ for(Argument arg : _args) {
+ String lookFor = null;
+ if(arg.isArgType())
+ if(arg.getArgname().equals(needle)) {
+ _flagsUsed.add(needle);
+ return true;
+ }
+ }
+ return false;
+ }
+
public String[] getUnusedArgs() {
// return (String[]) this.getUnusedArgsList().toArray();
List<Argument> als = this.getUnusedArgsList();
- String[] args = new String[als.size()];
- for(int x=0; x<als.size(); x++) {
+ // String[] args = new String[als.size()];
+ List<String> args = new ArrayList<String>();
+ int x=0;
+ while(x<als.size()) {
String tmp = "";
Argument arg = als.get(x);
- if(arg.getArgname()!=null) { tmp+=arg.getArgname()+":"; }
- if(arg.getArgvalue()!=null) tmp+=(String)arg.getArgvalue();
- args[x] = tmp;
+ if(is_Flag(arg)) {
+ boolean flagUsed = false;
+ if(arg.getArgname()!=null) {
+ flagUsed = _flagsUsed.contains(arg.getArgname());
+ if(!flagUsed) { args.add("-"+arg.getArgname()); }
+ }
+ if(arg.getArgvalue()!=null) { x++; tmp+=(String)arg.getArgvalue(); args.add(tmp); }
+ } else {
+ if(arg.getArgname()!=null) { tmp+=arg.getArgname()+":"; }
+ if(arg.getArgvalue()!=null) tmp+=(String)arg.getArgvalue();
+ args.add(tmp);
+ }
+ x++;
}
- return args;
+ return args.toArray(new String[0]);
}
public String[] getNormalArgs() {
List<Argument> al = this.getDefaultArguments();
String[] lijst = new String[al.size()];
- for(int x=0;x<al.size();x++)
+ for(int x=0;x<al.size();x++) {
lijst[x]=(String)al.get(x).getArgvalue();
+ }
return lijst;
}
-}
+}
View
112 src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java
@@ -98,7 +98,6 @@
private Object circendpoint = null;
private Object circadminendpoint = null;
-
private List<String> donottplist;
private List<String> MOTDLines;
@@ -110,6 +109,7 @@
private List<Player> mod_InfDuraplayers;
public String ToolDuraPattern = "§1§1§1§1";
+ public static TweakcraftUtils instance = null;
public File datafolder;
public Map<String, String> playerReplyDB;
@@ -119,15 +119,24 @@
public List<Player> getMod_InfDuraplayers() {
return mod_InfDuraplayers;
}
-
+
public PermissionsResolver getPermissions() {
return this.permsResolver;
}
-
+
public List<Player> getCUIPlayers() {
return cuiPlayers;
}
+ public static TweakcraftUtils getInstance() {
+ /* Do not create a new instance, could be dangerous! */
+ /* if(instance==null)
+ instance = new TweakcraftUtils(); */
+
+ return instance;
+ // return instance;
+ }
+
public void sendCUIChatMode(Player player) {
if(this.cuiPlayers != null && this.cuiPlayers.contains(player))
{
@@ -142,17 +151,17 @@ public void sendCUIChatMode(Player player) {
public LocalPlayer wrapPlayer(Player player) {
LocalPlayer p = this.wrapPlayer(player.getName());
- if(p.getBukkitPlayerSafe()==null)
+ if(p.getBukkitPlayer()==null)
p.setBukkitPlayer(player);
return p;
}
-
+
public LocalPlayer wrapPlayer(String player) {
- if(!this.localPlayers.containsKey(player))
- this.localPlayers.put(player, new LocalPlayer(player));
-
- return this.localPlayers.get(player);
+ if(!this.localPlayers.containsKey(player.toLowerCase()))
+ this.localPlayers.put(player.toLowerCase(), new LocalPlayer(player));
+
+ return this.localPlayers.get(player.toLowerCase());
}
public void sendCUIHandShake(Player player) {
@@ -160,7 +169,7 @@ public void sendCUIHandShake(Player player) {
player.sendRawMessage(CUIPattern); // HANDSHAKE
}
}
-
+
public void sendToolDuraMode(Player player) {
if(getConfigHandler().enablemod_InfDura && mod_InfDuraplayers.contains(player))
{
@@ -169,12 +178,12 @@ public void sendToolDuraMode(Player player) {
}
public void sendToolDuraMode(Player player, World to) {
- if(getConfigHandler().enablemod_InfDura && mod_InfDuraplayers.contains(player))
- {
- player.sendRawMessage(ToolDuraPattern+to.getToolDurability());
- }
+ if(getConfigHandler().enablemod_InfDura && mod_InfDuraplayers.contains(player))
+ {
+ player.sendRawMessage(ToolDuraPattern+to.getToolDurability());
}
-
+ }
+
public void sendmod_InfDuraHandshake(Player player) {
if(getConfigHandler().enablemod_InfDura) {
player.sendRawMessage(ToolDuraPattern);
@@ -262,31 +271,31 @@ else if (r < 338)
}
public void setupDatabase() {
- try {
- getDatabase().find(PlayerInfo.class).findRowCount();
- getDatabase().find(PlayerOptions.class).findRowCount();
- if(configHandler.useTweakBotSeen)
- getDatabase().find(PlayerHistoryInfo.class).findRowCount();
- } catch (PersistenceException ex) {
- log.info("[TweakcraftUtils] Installing database for " + getDescription().getName() + " due to first time usage");
- if(configHandler.useTweakBotSeen)
- log.info("[TweakcraftUtils] Also creating the TweakBot !seen helpen table");
- installDDL();
- }
- databaseloaded = true;
+ try {
+ getDatabase().find(PlayerInfo.class).findRowCount();
+ getDatabase().find(PlayerOptions.class).findRowCount();
+ if(configHandler.useTweakBotSeen)
+ getDatabase().find(PlayerHistoryInfo.class).findRowCount();
+ } catch (PersistenceException ex) {
+ log.info("[TweakcraftUtils] Installing database for " + getDescription().getName() + " due to first time usage");
+ if(configHandler.useTweakBotSeen)
+ log.info("[TweakcraftUtils] Also creating the TweakBot !seen helpen table");
+ installDDL();
+ }
+ databaseloaded = true;
}
public String listToString(List<String> lijst) {
- String res = "";
- if (lijst.size() != 0) {
- for (String s : lijst) {
- res += s + ",";
+ StringBuilder builder = new StringBuilder();
+ int c=0;
+ if(lijst.size()!=0) {
+ while(c<lijst.size()) {
+ builder.append(lijst.get(c));
+ if(c!=lijst.size()-1) builder.append(",");
+ c++;
}
- res = res.substring(0, res.length() - 1);
- } else {
- res = "";
}
- return res;
+ return builder.toString();
}
private List<String> toList(String str) {
@@ -302,6 +311,14 @@ public String listToString(List<String> lijst) {
return result;
}
+ public static List<Player> findPlayerByNick(String part) {
+ /* return getPlayerListener().findPlayerNameByNick(part); */
+ if(getInstance()!=null)
+ return getInstance().findPlayerasPlayerList(part);
+ else
+ return null;
+ }
+
public Player findPlayerasPlayer(String partOfName) {
// Go for the nicks first!
Player nick = playerListener.findPlayerByNick(partOfName);
@@ -315,17 +332,17 @@ public Player findPlayerasPlayer(String partOfName) {
// not found, just return partOfName
return nick;
}
-
+
/* public String getDisplayName(String name) {
return this.getNickWithColors(name);
} */
-
+
public Player getPlayer(String nick, boolean findNick) {
Player p = findNick?getPlayerByNick(nick):null;
if(p==null) p = this.getServer().getPlayerExact(nick);
return p;
}
-
+
public Player getPlayerByNick(String nick) {
return playerListener.findPlayerByNick(nick, true);
}
@@ -360,12 +377,13 @@ private void registerEvents() {
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_KICK, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
- getServer().getPluginManager().registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Priority.Normal, this);
+ getServer().getPluginManager().registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Priority.High, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_INTERACT_ENTITY, playerListener, Priority.Normal, this);
- getServer().getPluginManager().registerEvent(Event.Type.PLAYER_PORTAL, playerListener, Priority.Normal, this);
- getServer().getPluginManager().registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.Normal, this);
+ getServer().getPluginManager().registerEvent(Event.Type.PLAYER_PORTAL, playerListener, Priority.High, this);
+ getServer().getPluginManager().registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.High, this);
+ getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHANGED_WORLD, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.EXPLOSION_PRIME, entityListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.ENTITY_TARGET, entityListener, Priority.Normal, this);
@@ -435,7 +453,7 @@ public ChatHandler getChathandler() {
return lijst;
}
-
+
public void setupCraftIRC() {
if(this.getConfigHandler().enableIRC) {
Plugin plugin = this.getServer().getPluginManager().getPlugin("CraftIRC");
@@ -527,7 +545,7 @@ public String getNickWithColors(String player) {
/// return getPlayerColor(realname, false) + nick + ChatColor.WHITE;
return this.getPermissions().getResolver().getUserPrefix(player) + nick + ChatColor.WHITE;
}
-
+
public String getNick(String player) {
String nick = playerListener.getNick(player);
String realname = player;
@@ -555,6 +573,7 @@ public boolean hasNick(String player) {
public void onEnable() {
pdfFile = this.getDescription();
+ instance = this;
donottplist = new ArrayList<String>();
MOTDLines = new ArrayList<String>();
@@ -562,7 +581,7 @@ public void onEnable() {
configHandler.reloadConfig();
this.cuiPlayers = new ArrayList<Player>();
this.mod_InfDuraplayers = new ArrayList<Player>();
-
+
this.setupWorldGuard();
this.setupCraftIRC();
this.setupZones();
@@ -584,11 +603,11 @@ public void onEnable() {
playerListener.reloadInvisTable();
log.info("[" + pdfFile.getName() + "] " + pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
}
-
+
public EndPoint getEndPoint() {
return (EndPoint) circendpoint;
}
-
+
public EndPoint getAdminEndPoint() {
return (EndPoint) circadminendpoint;
}
@@ -598,6 +617,7 @@ public EndPoint getAdminEndPoint() {
}
public void onDisable() {
+ instance = null;
log.info("["+pdfFile.getName()+"] Shutting down!");
// this.getDatabase().
}
View
26 src/com/guntherdw/bukkit/tweakcraft/Worlds/TweakWorld.java
@@ -50,6 +50,7 @@
private boolean pvp = true;
private int viewdistance = 10;
private GameMode gamemode = null;
+ private String[] motd;
public TweakWorld(WorldManager wm, String foldername, org.bukkit.World.Environment env, boolean enabled) {
this.wm = wm;
@@ -208,25 +209,16 @@ public void loadWorld(WorldManager wm, String foldername, org.bukkit.World.Envir
fg.setNormal(normal);
fg.setToplayer(toplayer);
fg.assignWorldManager(wm);
- /* if(seed!=null)
- world = wm.getPlugin().getServer().createWorld(worldName, environment, seed, fg);
- else
- world = wm.getPlugin().getServer().createWorld(worldName, environment, fg); */
- // world = wm.getPlugin().getServer().createWorld()
worldCreator.generator(fg);
-
} else {
- /* if(seed!=null)
- world = wm.getPlugin().getServer().createWorld(worldName, environment, seed, cg); */
- // else
worldCreator.generator(cg);
}
} else {
- this.wm.getPlugin().getLogger().info("[TweakcraftUtils] Error in world"+worldName+"! "+chunkGen+" isn't a Chunk Generator class!");
+ this.wm.getPlugin().getLogger().info("[TweakcraftUtils] Error in world "+worldName+"! "+chunkGen+" isn't a Chunk Generator class!");
}
}
} catch (ClassNotFoundException e) {
- this.wm.getPlugin().getLogger().info("[TweakcraftUtils] Error in world"+worldName+"! Can't find class with name "+chunkGen);
+ this.wm.getPlugin().getLogger().info("[TweakcraftUtils] Error in world "+worldName+"! Can't find class with name "+chunkGen);
enabled=false;
} catch (InstantiationException e) {
enabled=false;
@@ -364,6 +356,18 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
+ public void setMOTD(String[] lines) {
+ this.motd = lines;
+ }
+
+ public String[] getMOTD() {
+ return this.motd;
+ }
+
+ public boolean hasWorldMOTD() {
+ return this.motd!=null && this.motd.length>0;
+ }
+
public void setPVP(boolean pvpallowed) {
this.pvp = pvpallowed;
this.world.setPVP(pvpallowed);
View
71 src/com/guntherdw/bukkit/tweakcraft/Worlds/WorldManager.java
@@ -21,7 +21,10 @@
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import org.bukkit.GameMode;
import org.bukkit.World.Environment;
+import org.bukkit.util.config.Configuration;
+import java.io.*;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -34,6 +37,7 @@
private Map<String, iWorld> worlds;
private TweakcraftUtils plugin;
private int defaultViewDistance;
+ private Configuration globalConfig = null;
public Map<String, iWorld> getWorlds() {
return worlds;
@@ -42,6 +46,30 @@
public int getDefaultViewDistance() {
return plugin.getServer().getViewDistance();
}
+
+
+ public void loadMotd(String worldname) {
+ if(!plugin.getConfigHandler().enableWorldMOTD || !worlds.containsKey(worldname)) return;
+
+ try{
+ File motd = new File(plugin.getDataFolder()+plugin.getConfigHandler().getDirSeperator()+"motd-"+worldname+".txt");
+ if(!motd.exists()) return;
+ BufferedReader fr = new BufferedReader(new FileReader(motd));
+ String line = null;
+ List<String> lines = new ArrayList<String>();
+ while((line = fr.readLine()) != null) {
+ lines.add(line.replace('&', '§'));
+ }
+
+ iWorld w = worlds.get(worldname);
+ w.setMOTD(lines.toArray(new String[0]));
+ plugin.getLogger().info("[TweakcraftUtils] Loaded MOTD for world "+worldname+"!");
+ } catch (FileNotFoundException e) {
+ plugin.getLogger().warning("[TweakcraftUtils] Couldn't find MOTD for world "+worldname+"!");
+ } catch (IOException e) {
+ plugin.getLogger().warning("[TweakcraftUtils] Error while reading MOTD for world "+worldname+"!");
+ }
+ }
public WorldManager(TweakcraftUtils instance) {
this.plugin = instance;
@@ -49,10 +77,13 @@ public WorldManager(TweakcraftUtils instance) {
}
public void setupWorlds() {
+
+ if(globalConfig==null) globalConfig = plugin.getConfigHandler().getGlobalconfig();
+
boolean netherWorldOnline = false;
- List<String> extraworlds = plugin.getConfiguration().getKeys("worlds.extraworlds");
+ List<String> extraworlds = globalConfig.getKeys("worlds.extraworlds");
- Boolean worldInfDura = plugin.getConfiguration().getBoolean("worlds.durability", true);
+ Boolean worldInfDura = globalConfig.getBoolean("worlds.durability", true);
int defaultviewdistance = this.getDefaultViewDistance();
for (org.bukkit.World world : plugin.getServer().getWorlds()) {
@@ -67,8 +98,8 @@ public void setupWorlds() {
netherWorldOnline = true;
}
- if (netherWorldOnline == false && plugin.getConfiguration().getBoolean("worlds.enablenether", false)) {
- String netherfolder = plugin.getConfiguration().getString("worlds.netherfolder", "nether");
+ if (netherWorldOnline == false && globalConfig.getBoolean("worlds.enablenether", false)) {
+ String netherfolder = globalConfig.getString("worlds.netherfolder", "nether");
if (!netherfolder.equalsIgnoreCase("")) {
plugin.getLogger().info("[TweakcraftUtils] Loading the netherworld!");
worlds.put(netherfolder, new TweakWorld(this, netherfolder, Environment.NETHER, true));
@@ -76,27 +107,25 @@ public void setupWorlds() {
plugin.getLogger().info("[TweakcraftUtils] The nether's folder name can't be empty!");
}
}
- // List<String> extraworlds = plugin.getConfiguration().getKeys("worlds.extraworlds");
-
for (String node : extraworlds) {
if (!worlds.containsKey(node)) {
- String env = plugin.getConfiguration().getString("worlds.extraworlds." + node + ".environment", "");
- boolean enabled = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".enabled", false);
- boolean pvp = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".pvp", false);
- boolean monsters = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".monsters", true);
- boolean animals = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".animals", true);
- boolean durability = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".durability", true);
- boolean addnether = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".addnether", false);
- boolean spawnchunksactive = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".spawnchunksactive", false);
- String chunkGen = plugin.getConfiguration().getString("worlds.extraworlds." + node + ".chunkGenerator", null);
- int viewdistance = plugin.getConfiguration().getInt("worlds.extraworlds." + node + ".viewdistance", defaultviewdistance);
- int portalSearchRadius = plugin.getConfiguration().getInt("worlds.extraworlds." + node + ".portalSearchRadius", 128);
- long seed = plugin.getConfiguration().getInt("worlds.extraworlds." + node + ".seed", -1);
- long nseed = plugin.getConfiguration().getInt("worlds.extraworlds." + node + ".netherseed", -1);
+ String env = globalConfig.getString("worlds.extraworlds." + node + ".environment", "");
+ boolean enabled = globalConfig.getBoolean("worlds.extraworlds." + node + ".enabled", false);
+ boolean pvp = globalConfig.getBoolean("worlds.extraworlds." + node + ".pvp", false);
+ boolean monsters = globalConfig.getBoolean("worlds.extraworlds." + node + ".monsters", true);
+ boolean animals = globalConfig.getBoolean("worlds.extraworlds." + node + ".animals", true);
+ boolean durability = globalConfig.getBoolean("worlds.extraworlds." + node + ".durability", true);
+ boolean addnether = globalConfig.getBoolean("worlds.extraworlds." + node + ".addnether", false);
+ boolean spawnchunksactive = globalConfig.getBoolean("worlds.extraworlds." + node + ".spawnchunksactive", false);
+ String chunkGen = globalConfig.getString("worlds.extraworlds." + node + ".chunkGenerator", null);
+ int viewdistance = globalConfig.getInt("worlds.extraworlds." + node + ".viewdistance", defaultviewdistance);
+ int portalSearchRadius = globalConfig.getInt("worlds.extraworlds." + node + ".portalSearchRadius", 128);
+ long seed = globalConfig.getInt("worlds.extraworlds." + node + ".seed", -1);
+ long nseed = globalConfig.getInt("worlds.extraworlds." + node + ".netherseed", -1);
- String gameMode = plugin.getConfiguration().getString("worlds.extraworlds." + node + ".gamemode", null);
+ String gameMode = globalConfig.getString("worlds.extraworlds." + node + ".gamemode", null);
GameMode gm = gameMode!=null?GameMode.valueOf(gameMode.toUpperCase()):null;
/* if(gameMode==null || gameMode.equals("")) {
@@ -145,7 +174,7 @@ public void setupWorlds() {
}
worlds.put(node, tw);
-
+ this.loadMotd(tw.getName());
} else {
plugin.getLogger().info("[TweakcraftUtils] " + env + " isn't a correct environment name!");
}
View
3  src/com/guntherdw/bukkit/tweakcraft/Worlds/iWorld.java
@@ -55,5 +55,8 @@
public void setAllowMonsters(boolean allowmonsters);
public void setSpawnFlags(boolean allowMonsters, boolean allowAnimals);
public void setEnabled(boolean enabled);
+ public void setMOTD(String[] lines);
+ public String[] getMOTD();
+ public boolean hasWorldMOTD();
public FileConfiguration getConfiguration();
}
Please sign in to comment.
Something went wrong with that request. Please try again.