Reworked border bypass to be toggleable by command, instead of always on if player had the permission like it was.

New command /wb bypass [player] [on/off], which allows the player to go beyond the border without being knocked back. Requires "worldborder.bypass" permission (Ops only by default). Nobody has bypass mode enabled by default (has to be toggled on), and the list of people with bypass enabled is wiped on server restarts. Player name ("[player]") is optional if run in-game and defaults to the player running the command, but must be specified if run from console. If on or off ("[on/off]") is not specified, it will simply be toggled.
This commit is contained in:
Brettflan 2012-11-05 11:35:37 -06:00
parent caa3db3734
commit b41267af1a
4 changed files with 72 additions and 9 deletions

View File

@ -52,8 +52,8 @@ public class BorderCheckTask implements Runnable
if (border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound()))
return null;
// if player has "worldborder.bypass" permission, allow them beyond border
if (Config.HasPermission(player, "bypass", false))
// if player is in bypass list (from bypass command), allow them beyond border
if (Config.isPlayerBypassing(player.getName()))
return null;
Location newLoc = newLocation(player, loc, border);

View File

@ -2,9 +2,10 @@ package com.wimbli.WorldBorder;
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Map;
@ -26,7 +27,7 @@ public class Config
private static int borderTask = -1;
public static WorldFillTask fillTask;
public static WorldTrimTask trimTask;
public static Set<String> movedPlayers = Collections.synchronizedSet(new HashSet<String>());
private static Set<String> bypassPlayers = Collections.synchronizedSet(new LinkedHashSet<String>());
private static Runtime rt = Runtime.getRuntime();
// actual configuration values which can be changed
@ -215,6 +216,24 @@ public class Config
return dynmapMessage;
}
public static void setPlayerBypass(String player, boolean bypass)
{
if (bypass)
bypassPlayers.add(player.toLowerCase());
else
bypassPlayers.remove(player.toLowerCase());
}
public static boolean isPlayerBypassing(String player)
{
return bypassPlayers.contains(player.toLowerCase());
}
public static void togglePlayerBypass(String player)
{
setPlayerBypass(player, !isPlayerBypassing(player));
}
public static void StartBorderTimer()

View File

@ -5,6 +5,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
@ -325,7 +326,7 @@ public class WBCommand implements CommandExecutor
Config.Log((Config.Debug() ? "Enabling" : "Disabling") + " debug output at the command of player \"" + player.getName() + "\".");
if (player != null)
sender.sendMessage("Debug mode " + (Config.Debug() ? "enabled" : "disabled") + ".");
sender.sendMessage("Debug mode " + enabledColored(Config.Debug()) + ".");
}
// "whoosh" command from player or console
@ -339,7 +340,7 @@ public class WBCommand implements CommandExecutor
Config.Log((Config.whooshEffect() ? "Enabling" : "Disabling") + " \"whoosh\" knockback effect at the command of player \"" + player.getName() + "\".");
if (player != null)
sender.sendMessage("\"Whoosh\" knockback effect " + (Config.whooshEffect() ? "enabled" : "disabled") + ".");
sender.sendMessage("\"Whoosh\" knockback effect " + enabledColored(Config.whooshEffect()) + ".");
}
// "knockback" command from player or console
@ -563,7 +564,7 @@ public class WBCommand implements CommandExecutor
Config.setDynmapBorderEnabled(strAsBool(split[1]));
sender.sendMessage("DynMap border display " + (Config.Debug() ? "enabled" : "disabled") + ".");
sender.sendMessage("DynMap border display " + (Config.DynmapBorderEnabled() ? "enabled" : "disabled") + ".");
if (player != null)
Config.Log((Config.DynmapBorderEnabled() ? "Enabled" : "Disabled") + " DynMap border display at the command of player \"" + player.getName() + "\".");
@ -591,6 +592,42 @@ public class WBCommand implements CommandExecutor
}
}
// "bypass" command from player or console, player specified, on/off optionally specified
else if (split.length >= 2 && split[0].equalsIgnoreCase("bypass"))
{
if (!Config.HasPermission(player, "bypass")) return true;
String sPlayer = split[1];
boolean bypassing = !Config.isPlayerBypassing(sPlayer);
if (split.length > 2)
bypassing = strAsBool(split[2]);
Config.setPlayerBypass(sPlayer, bypassing);
Player target = Bukkit.getPlayer(sPlayer);
if (target != null && target.isOnline())
target.sendMessage("Border bypass is now " + enabledColored(bypassing) + ".");
Config.Log("Border bypass for player \"" + sPlayer + "\" is " + (bypassing ? "enabled" : "disabled") + (player != null ? " at the command of player \"" + player.getName() + "\"" : "") + ".");
if (player != null && player != target)
sender.sendMessage("Border bypass for player \"" + sPlayer + "\" is " + enabledColored(bypassing) + ".");
}
// "bypass" command from player, using them for player
else if (split.length == 1 && split[0].equalsIgnoreCase("bypass") && player != null)
{
if (!Config.HasPermission(player, "bypass")) return true;
String sPlayer = player.getName();
boolean bypassing = !Config.isPlayerBypassing(sPlayer);
Config.setPlayerBypass(sPlayer, bypassing);
Config.Log("Border bypass is " + (bypassing ? "enabled" : "disabled") + " for player \"" + sPlayer + "\".");
sender.sendMessage("Border bypass is now " + enabledColored(bypassing) + ".");
}
// we couldn't decipher any known commands, so show help
else
{
@ -630,17 +667,18 @@ public class WBCommand implements CommandExecutor
{
sender.sendMessage(cmdW+" fill " + clrOpt + "[freq] [pad]" + clrDesc + " - generate world out to border.");
sender.sendMessage(cmdW+" trim " + clrOpt + "[freq] [pad]" + clrDesc + " - trim world outside of border.");
sender.sendMessage(cmd+" bypass " + ((player == null) ? clrReq + "<player>" : clrOpt + "[player]") + clrOpt + " [on/off]" + clrDesc + " - let player go beyond border.");
sender.sendMessage(cmd+" wshape " + ((player == null) ? clrReq + "<world>" : clrOpt + "[world]") + clrReq + " <round|square|default>" + clrDesc + " - shape override.");
sender.sendMessage(cmd+" getmsg" + clrDesc + " - display border message.");
sender.sendMessage(cmd+" setmsg " + clrReq + "<text>" + clrDesc + " - set border message.");
sender.sendMessage(cmd+" whoosh " + clrReq + "<on|off>" + clrDesc + " - turn knockback effect on or off.");
sender.sendMessage(cmd+" delay " + clrReq + "<amount>" + clrDesc + " - time between border checks.");
sender.sendMessage(cmd+" reload" + clrDesc + " - re-load data from config.yml.");
if (page == 2)
sender.sendMessage(cmd+" 3" + clrDesc + " - view third page of commands.");
}
if (page == 0 || page == 3)
{
sender.sendMessage(cmd+" reload" + clrDesc + " - re-load data from config.yml.");
sender.sendMessage(cmd+" dynmap " + clrReq + "<on|off>" + clrDesc + " - turn DynMap border display on or off.");
sender.sendMessage(cmd+" dynmapmsg " + clrReq + "<text>" + clrDesc + " - DynMap border labels will show this.");
sender.sendMessage(cmd+" debug " + clrReq + "<on|off>" + clrDesc + " - turn console debug output on or off.");
@ -663,6 +701,11 @@ public class WBCommand implements CommandExecutor
return false;
}
private String enabledColored(boolean enabled)
{
return enabled ? clrReq+"enabled" : clrErr+"disabled";
}
private boolean cmdSet(CommandSender sender, String world, String[] data, int offset)
{
int radius;

View File

@ -26,6 +26,7 @@ commands:
/<command> wshape [world] <round|square|default> - override shape.
/<command> [world] fill [freq] [pad] - generate world out to border.
/<command> [world] trim [freq] [pad] - trim world outside of border.
/<command> bypass [player] [on/off] - let player go beyond border.
/<command> dynmap <on/off> - turn DynMap border display on or off.
/<command> dynmapmsg <text> - DynMap border labels will show this.
/<command> debug <on/off> - turn debug mode on or off.
@ -107,4 +108,4 @@ permissions:
default: op
worldborder.bypass:
description: Can go beyond the border without being knocked back
default: false
default: op