Skip to content

Commit

Permalink
Added per-world MOTD support,
Browse files Browse the repository at this point in the history
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
GuntherDW committed Nov 12, 2011
1 parent f77e052 commit 88bbd9d
Show file tree
Hide file tree
Showing 24 changed files with 418 additions and 268 deletions.
4 changes: 0 additions & 4 deletions src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java
Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
Expand Up @@ -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!
{
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Expand Up @@ -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;
Expand All @@ -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!");
Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -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?" ":"");
}


Expand Down
Expand Up @@ -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();

Expand Down
Expand Up @@ -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"))
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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!");
}


Expand Down
Expand Up @@ -76,6 +76,7 @@ public class ConfigurationHandler {
public boolean enablemod_InfDura = false;
public boolean enableExperienceOrbsHalt = false;
public boolean enableTargetIgnoreAFKPlayers = false;
public boolean enableWorldMOTD = false;

// public PermissionsResolver.PermissionResolvingMode permissoinsResolvingMode = null;

Expand Down Expand Up @@ -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);
Expand All @@ -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)) {
Expand All @@ -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!");
Expand Down Expand Up @@ -249,4 +231,8 @@ public Map<String, Map<Integer, Boolean>> getLsbindmap() {
public Map<String, LockdownLocation> getLockdowns() {
return lockdowns;
}

public String getDirSeperator() {
return System.getProperty("file.separator");
}
}
Expand Up @@ -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) {
Expand Down

0 comments on commit 88bbd9d

Please sign in to comment.