Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Trying to fix /tpoff yet again,

Adding custom events (untested code!)
  • Loading branch information...
commit f47bc8fe0a236d8322b1825c6a5e77395a0cc4bd 1 parent 9a942ad
GuntherDW authored
6 src/com/guntherdw/bukkit/tweakcraft/Chat/ChatMode.java
View
@@ -172,9 +172,9 @@ public String getLoggingFormatString() {
}
public String getLoggingFormatStringNoPlayerTag() {
- String name = this.chatModeName == null ? getClass().getSimpleName() : chatModeName;
- return name + ": %1$s";
- }
+ String name = this.chatModeName == null ? getClass().getSimpleName() : chatModeName;
+ return name + ": %1$s";
+ }
public String getChatFormatString() {
String prefix = getPrefix();
40 src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/TeleportationCommands.java
View
@@ -666,13 +666,15 @@ public boolean tpOffCommand(CommandSender sender, String command, String[] args)
if (!plugin.check((Player) sender, "tpoff"))
throw new PermissionsException(command);
+ LocalPlayer lp = plugin.wrapPlayer((Player) sender);
+
if (args.length != 0 && !args[0].equalsIgnoreCase(((Player) sender).getName())) {
if (!plugin.check((Player) sender, "tpoffother"))
throw new PermissionsException(command);
this.tpoff(plugin, sender, args[0]);
} else {
- if (!plugin.getDonottplist().contains(((Player) sender).getName())) {
- plugin.getDonottplist().add(((Player) sender).getName());
+ if(!lp.isTpOff()) {
+ lp.setTpOff(true);
sender.sendMessage(ChatColor.YELLOW + "They can no longer tp to you!");
} else {
sender.sendMessage(ChatColor.YELLOW + "You already are on the do-not-tp list!");
@@ -688,14 +690,16 @@ public boolean tpOffCommand(CommandSender sender, String command, String[] args)
}
private void tpoff(TweakcraftUtils plugin, CommandSender sender, String player) {
- String playername = plugin.findPlayer(player);
- if (!plugin.getDonottplist().contains(playername)) {
- plugin.getDonottplist().add(playername);
- LocalPlayer lp = plugin.wrapPlayer(playername);
+ Player p = plugin.findPlayerasPlayer(player);
+ if(p==null) return;
+ LocalPlayer lp = plugin.wrapPlayer(p);
+ // LocalPlayer lp = plugin.wrapPlayer(playername);
+
+ if (!lp.isTpOff()) {
lp.setTpOff(true);
- sender.sendMessage(ChatColor.GREEN + "They can no longer tp to " + playername + "!");
+ sender.sendMessage(ChatColor.GREEN + "They can no longer tp to " + p.getDisplayName() + ChatColor.GREEN + "!");
} else {
- sender.sendMessage(ChatColor.GREEN + playername + " already is on the do-not-tp list!");
+ sender.sendMessage(ChatColor.GREEN + p.getDisplayName() + ChatColor.GREEN + " already is on the do-not-tp list!");
}
}
@@ -711,13 +715,15 @@ public boolean tpOnCommand(CommandSender sender, String command, String[] args)
if (!plugin.check((Player) sender, "tpoff"))
throw new PermissionsException(command);
+ LocalPlayer lp = plugin.wrapPlayer((Player) sender);
+
if (args.length != 0 && !args[0].equalsIgnoreCase(((Player) sender).getName())) {
if (!plugin.check((Player) sender, "tpoffother"))
throw new PermissionsException(command);
this.tpon(plugin, sender, args[0]);
} else {
- if (plugin.getDonottplist().contains(((Player) sender).getName())) {
- plugin.getDonottplist().remove(((Player) sender).getName());
+ if (lp.isTpOff()) {
+ lp.setTpOff(false);
sender.sendMessage(ChatColor.YELLOW + "They can now tp to you!");
} else {
sender.sendMessage(ChatColor.YELLOW + "You aren't on the do-not-tp list!");
@@ -733,14 +739,16 @@ public boolean tpOnCommand(CommandSender sender, String command, String[] args)
}
private void tpon(TweakcraftUtils plugin, CommandSender sender, String player) {
- String playername = plugin.findPlayer(player);
- if (plugin.getDonottplist().contains(playername)) {
- plugin.getDonottplist().remove(playername);
- LocalPlayer lp = plugin.wrapPlayer(playername);
+ Player p = plugin.findPlayerasPlayer(player);
+ if(p==null) return;
+ LocalPlayer lp = plugin.wrapPlayer(p);
+ // LocalPlayer lp = plugin.wrapPlayer(playername);
+
+ if (lp.isTpOff()) {
lp.setTpOff(false);
- sender.sendMessage(ChatColor.GREEN + "They can now tp to " + playername + "!");
+ sender.sendMessage(ChatColor.GREEN + "They can now tp to " + p.getDisplayName() + ChatColor.GREEN + "!");
} else {
- sender.sendMessage(ChatColor.GREEN + "I can't find " + playername + " in the do-not-tp list!");
+ sender.sendMessage(ChatColor.GREEN + "I can't find " + p.getDisplayName() + ChatColor.GREEN + " in the do-not-tp list!");
}
}
}
68 src/com/guntherdw/bukkit/tweakcraft/Events/TweakcraftUtilsEvent.java
View
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2011 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.Events;
+
+import com.guntherdw.bukkit.tweakcraft.Packages.LocalPlayer;
+import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+
+
+public class TweakcraftUtilsEvent extends Event {
+
+ protected Action action;
+ private LocalPlayer player;
+ private static final HandlerList handlers = new HandlerList();
+
+ public TweakcraftUtilsEvent(Action action) {
+ this.action = action;
+ }
+
+ public LocalPlayer getPlayer() {
+ return player;
+ }
+
+ public void setPlayer(LocalPlayer player) {
+ this.player = player;
+ }
+
+ public void setPlayer(Player player) {
+ TweakcraftUtils.getInstance().wrapPlayer(player);
+ }
+
+ public Action getAction() {
+ return this.action;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ public enum Action {
+ CHATMODE_CHANGED,
+ NICK_CHANGED,
+ RELOAD_INFO
+ }
+}
53 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java
View
@@ -24,6 +24,7 @@
import com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass.PlayerHistoryInfo;
import com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass.PlayerInfo;
import com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass.PlayerOptions;
+import com.guntherdw.bukkit.tweakcraft.Events.TweakcraftUtilsEvent;
import com.guntherdw.bukkit.tweakcraft.Exceptions.ChatModeException;
import com.guntherdw.bukkit.tweakcraft.Packages.Ban;
import com.guntherdw.bukkit.tweakcraft.Packages.LocalPlayer;
@@ -43,7 +44,6 @@
import org.bukkit.event.block.Action;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
-import org.bukkit.scheduler.BukkitScheduler;
import java.io.IOException;
import java.lang.reflect.Method;
@@ -154,11 +154,14 @@ public void setNick(String player, String nick) {
plugin.getDatabase().save(pi);
}
- if (plugin.getClientBridge() != null) {
+ /* if (plugin.getClientBridge() != null) {
for(Player p : plugin.getServer().getOnlinePlayers()) {
plugin.getClientBridge().getPlayerListener().sendPlayerInfo(p, lp.getBukkitPlayerSafe().getName(), true);
}
- }
+ } */
+ TweakcraftUtilsEvent event = new TweakcraftUtilsEvent(TweakcraftUtilsEvent.Action.NICK_CHANGED);
+ event.setPlayer(lp);
+ plugin.getServer().getPluginManager().callEvent(event);
}
public boolean removeNick(String player) {
@@ -177,11 +180,15 @@ public boolean removeNick(String player) {
lp.setNick(null);
plugin.getDatabase().update(pi);
}
- if (plugin.getClientBridge() != null) {
+ /* if (plugin.getClientBridge() != null) {
for(Player p : plugin.getServer().getOnlinePlayers()) {
plugin.getClientBridge().getPlayerListener().sendPlayerInfo(p, lp.getBukkitPlayerSafe().getName(), true);
}
- }
+ } */
+ TweakcraftUtilsEvent event = new TweakcraftUtilsEvent(TweakcraftUtilsEvent.Action.NICK_CHANGED);
+ event.setPlayer(lp);
+ plugin.getServer().getPluginManager().callEvent(event);
+
return true;
} else {
System.out.println("NOT doing nicks.remove");
@@ -327,9 +334,10 @@ public void reloadInfo() {
capes.put(po.getName(), po.getOptionvalue());
}
}
- if(plugin.getClientBridge() != null) {
+ /* if(plugin.getClientBridge() != null) {
plugin.getClientBridge().getPlayerListener().reloadInfo();
- }
+ } */
+ plugin.getServer().getPluginManager().callEvent(new TweakcraftUtilsEvent(TweakcraftUtilsEvent.Action.RELOAD_INFO));
}
public Map<String, String> getNicks() {
@@ -485,6 +493,7 @@ public void onPlayerLogin(PlayerLoginEvent event) {
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
+ LocalPlayer lp = plugin.wrapPlayer(p);
String name = p.getName();
String displayName = plugin.getNickWithColors(p.getName());
String ldisplayname = displayName.substring(0, displayName.length() - 2);
@@ -500,12 +509,9 @@ public void onPlayerJoin(PlayerJoinEvent event) {
p.sendMessage(m);
}
+ event.setJoinMessage(ChatColor.YELLOW + displayName + ChatColor.YELLOW +" joined the game.");
- if (plugin.hasNick(name)) {
- event.setJoinMessage(ChatColor.YELLOW + displayName + ChatColor.YELLOW +" joined the game.");
- }
-
- if (getInvisplayers().contains(event.getPlayer().getName())) { // Invisible players do not send out a "joined" message
+ if (lp.isInvisible()) { // Invisible players do not send out a "joined" message
event.setJoinMessage(null);
p.sendMessage(ChatColor.AQUA + "You has joined STEALTHILY!");
for (Player play : plugin.getServer().getOnlinePlayers()) {
@@ -547,6 +553,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
+ LocalPlayer lp = plugin.wrapPlayer(player);
String name = player.getName();
if (plugin.getConfigHandler().enableSeenConfig) {
@@ -597,7 +604,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage(ChatColor.YELLOW + player.getDisplayName() + ChatColor.YELLOW + " left the game.");
// }
- if (getInvisplayers().contains(name)) { // Invisible players do not send out a "left" message
+ if (lp.isInvisible()) { // Invisible players do not send out a "left" message
event.setQuitMessage(null);
/* if (plugin.getCraftIRC() != null) {
plugin.getCraftIRC().sendMessageToTag("STEALTH QUIT : " +name ,"mchatadmin");
@@ -706,24 +713,26 @@ public void run() {
}
public void reloadInvisTable() {
- List<String> lijst = plugin.getConfig().getStringList("invisible.playerList");
+ List<String> lijst = plugin.getConfigHandler().getGlobalconfig().getStringList("invisible.playerList");
+
+ for (String s : this.invisplayers) {
+ LocalPlayer lp = plugin.wrapPlayer(s);
+ plugin.getLogger().info("[TweakcraftUtils] Removing " + s + " from the invisble playerlist!");
+ lp.setInvisible(false);
+ }
+ 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);
+ if (lijst != null) {
+ 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)
+ // if (plugin.getConfigHandler().enableDebug)
plugin.getLogger().info("[TweakcraftUtils] Adding " + s + " to the invisble playerlist!");
}
}
25 src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java
View
@@ -22,7 +22,7 @@
import com.ensifera.animosity.craftirc.CraftIRC;
import com.ensifera.animosity.craftirc.EndPoint;
-import com.guntherdw.bukkit.tcutilsclientbridge.TCUtilsClientBridgePlugin;
+// import com.guntherdw.bukkit.tcutilsclientbridge.TCUtilsClientBridgePlugin;
import com.guntherdw.bukkit.tweakcraft.Chat.ChatHandler;
import com.guntherdw.bukkit.tweakcraft.Chat.ChatMode;
import com.guntherdw.bukkit.tweakcraft.Commands.CommandHandler;
@@ -31,10 +31,7 @@
import com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass.PlayerHistoryInfo;
import com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass.PlayerInfo;
import com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass.PlayerOptions;
-import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandException;
-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.Events.TweakcraftUtilsEvent;
import com.guntherdw.bukkit.tweakcraft.Listeners.*;
import com.guntherdw.bukkit.tweakcraft.Packages.CraftIRCAdminEndPoint;
import com.guntherdw.bukkit.tweakcraft.Packages.CraftIRCEndPoint;
@@ -78,7 +75,7 @@
protected Zones zones = null;
protected LogBlock lb = null;
protected WorldEditPlugin we = null;
- protected TCUtilsClientBridgePlugin tcUtilsClientBridgePlugin = null;
+ // protected TCUtilsClientBridgePlugin tcUtilsClientBridgePlugin = null;
// protected NoLagg nolagg = null;
// protected PermissionHandler ph = null;
@@ -142,14 +139,14 @@ public static TweakcraftUtils getInstance() {
return instance;
}
- public TCUtilsClientBridgePlugin getClientBridge() {
+ /* public TCUtilsClientBridgePlugin getClientBridge() {
return tcUtilsClientBridgePlugin;
}
public static void registerClientBridge(TCUtilsClientBridgePlugin clientBridgePlugin) {
if(instance==null) return;
instance.tcUtilsClientBridgePlugin = clientBridgePlugin;
- }
+ } */
public void sendCUIChatMode(Player player) {
if (this.cuiPlayers != null && this.cuiPlayers.contains(player)) {
@@ -160,8 +157,11 @@ public void sendCUIChatMode(Player player) {
else
player.sendRawMessage(CUIPattern + "[" + cm.getPrefix() + "]");
}
- if(tcUtilsClientBridgePlugin != null)
- tcUtilsClientBridgePlugin.sendChatMode(player);
+ /* if(tcUtilsClientBridgePlugin != null)
+ tcUtilsClientBridgePlugin.sendChatMode(player); */
+ TweakcraftUtilsEvent event = new TweakcraftUtilsEvent(TweakcraftUtilsEvent.Action.CHATMODE_CHANGED);
+ event.setPlayer(wrapPlayer(player));
+ this.getServer().getPluginManager().callEvent(event);
}
public LocalPlayer wrapPlayer(Player player) {
@@ -204,8 +204,9 @@ public void sendToolDuraMode(Player player, World world) {
if (getConfigHandler().enablemod_InfDura && mod_InfDuraplayers.contains(player)) {
player.sendRawMessage(ToolDuraPattern + world.getToolDurability());
}
- if(tcUtilsClientBridgePlugin != null)
- tcUtilsClientBridgePlugin.getPlayerListener().sendToolDuraMode(player, world);
+ /* if(tcUtilsClientBridgePlugin != null)
+ tcUtilsClientBridgePlugin.getPlayerListener().sendToolDuraMode(player, world); */
+
}
/**
1  src/com/guntherdw/bukkit/tweakcraft/Worlds/TweakWorld.java
View
@@ -219,7 +219,6 @@ public void loadWorld(WorldManager wm, String foldername, org.bukkit.World.Envir
if ((world = wm.getPlugin().getServer().getWorld(worldName)) == null) {
// wm.getPlugin().getLogger().info("[TweakcraftUtils] Creating new world!");
environment = env;
-
if (chunkgen != null)
worldCreator.generator(chunkgen);
Please sign in to comment.
Something went wrong with that request. Please try again.