Skip to content
Browse files

Tried to fix tpback issues AGAIN,

fixed some CraftIRC admin endpoint issues
Added "do not target when afk" option for AFK players
  • Loading branch information...
1 parent 199b65e commit f77e052296645ff3a0be09a6a289a08cafcbbc7f @GuntherDW committed Nov 6, 2011
View
5 src/com/guntherdw/bukkit/tweakcraft/Commands/Admin/CommandTC.java
@@ -68,8 +68,9 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
String displayName = plugin.getNickWithColors(p.getName());
String ldisplayname = displayName.substring(0, displayName.length()-2);
p.setDisplayName(displayName);
- if(ldisplayname.length()<=16)
- p.setPlayerListName(ldisplayname);
+ if(ldisplayname.length()<=16) {
+ try{ p.setPlayerListName(ldisplayname); } catch(IllegalArgumentException ex) { ; }
+ }
}
plugin.getPlayerListener().reloadInvisTable();
/**
View
18 src/com/guntherdw/bukkit/tweakcraft/Commands/Teleportation/CommandTPBack.java
@@ -29,6 +29,8 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.util.List;
+
/**
* @author GuntherDW
@@ -58,6 +60,22 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
player.sendMessage(ChatColor.YELLOW + "You don't have any tpback lines!");
}
go=false;
+ } else if(args[0].equalsIgnoreCase("debug")) {
+ int pos = 0;
+ String s = "";
+ int offs = plugin.getTelehistory().getOffset(player.getName());
+ List<Location> loclist = plugin.getTelehistory().getHistoryList(player.getName());
+ if(loclist!=null) {
+ // player.sendMessage(ChatColor.GOLD + "offs : "+offs);
+ if(offs==-1) offs = loclist.size()-1; else offs = loclist.size()-offs;
+ // player.sendMessage(ChatColor.GOLD +"size : "+loclist.size());
+ for(Location l : loclist) {
+ s = "world: "+l.getWorld().getName()+" x:"+Math.floor(l.getX())+" y:"+Math.floor(l.getY())+" z:"+Math.floor(l.getZ());
+ player.sendMessage( (pos==offs?"--> ":"") +ChatColor.GOLD + s);
+ pos++;
+ }
+ }
+ go = false;
}
}
View
2 src/com/guntherdw/bukkit/tweakcraft/Configuration/ConfigurationHandler.java
@@ -75,6 +75,7 @@
public boolean enableCUI = false;
public boolean enablemod_InfDura = false;
public boolean enableExperienceOrbsHalt = false;
+ public boolean enableTargetIgnoreAFKPlayers = false;
// public PermissionsResolver.PermissionResolvingMode permissoinsResolvingMode = null;
@@ -198,6 +199,7 @@ public void reloadConfig() {
this.enableCUI = globalconfig.getBoolean("extra.CUI", false);
this.enablemod_InfDura = globalconfig.getBoolean("extra.mod_InfDura", false);
this.enableExperienceOrbsHalt = globalconfig.getBoolean("extra.stopExperienceOrbs", false);
+ this.enableTargetIgnoreAFKPlayers = globalconfig.getBoolean("extra.targetIgnoreAFK", false);
this.cancelNickChat = globalconfig.getBoolean("extra.cancelNickChat", true);
this.extraLogging = globalconfig.getBoolean("extra.extraLogging", false);
View
21 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftEntityListener.java
@@ -18,15 +18,13 @@
package com.guntherdw.bukkit.tweakcraft.Listeners;
+import com.guntherdw.bukkit.tweakcraft.Packages.LocalPlayer;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
-import org.bukkit.event.entity.EntityCombustEvent;
-import org.bukkit.event.entity.EntityDeathEvent;
-import org.bukkit.event.entity.EntityListener;
-import org.bukkit.event.entity.ExplosionPrimeEvent;
+import org.bukkit.event.entity.*;
import org.bukkit.inventory.ItemStack;
@@ -41,6 +39,17 @@ public TweakcraftEntityListener(TweakcraftUtils instance) {
this.plugin = instance;
}
+ public void onEntityTarget(EntityTargetEvent event) {
+ if(!plugin.getConfigHandler().enableTargetIgnoreAFKPlayers) return;
+ if(event.isCancelled()) return;
+ if(!(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)) {
+ if(lp.isAfk()) event.setCancelled(true);
+ }
+ }
+
public void onEntityCombust(EntityCombustEvent event) {
if(!plugin.getConfigHandler().stopIgniteWorldGuard) return;
Entity ent = event.getEntity();
@@ -63,7 +72,7 @@ public void onEntityDeath(EntityDeathEvent event) {
event.getDrops().add(new ItemStack(Material.SADDLE, 1));
}
}
-
+
if(plugin.getConfigHandler().enableExperienceOrbsHalt) {
event.setDroppedExp(0);
}
@@ -72,7 +81,7 @@ public void onEntityDeath(EntityDeathEvent event) {
public void onExplosionPrime(ExplosionPrimeEvent event) {
if(event.isCancelled())
return;
-
+
Entity ent = event.getEntity();
if(ent != null)
{
View
17 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java
@@ -151,14 +151,18 @@ public String getNick(String player) {
}
}
- public Player findPlayerByNick(String nick) {
+ 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;
String n = null;
for(String part : nicks.keySet()) {
n = nicks.get(part);
- if(n.toLowerCase().contains(nick.toLowerCase())) {
+ if(exact ? n.toLowerCase().equals(nick.toLowerCase()) : n.toLowerCase().contains(nick.toLowerCase())) {
p = part;
}
}
@@ -183,15 +187,16 @@ public Player findPlayerByNick(String nick) {
return playerlijst;
}
- public String findPlayerNameByNick(String nick) {
+ public String findPlayerNameByNick(String nick, boolean strict) {
String p = null;
String n = null;
for(String part : nicks.keySet()) {
n = nicks.get(part);
- if(n.toLowerCase().contains(nick.toLowerCase())) {
+ if(strict? n.toLowerCase().equals(nick.toLowerCase()) : n.toLowerCase().contains(nick.toLowerCase())) {
p = part;
+ if(strict) return p;
}
}
@@ -276,7 +281,7 @@ public void onPlayerChat(PlayerChatEvent event) {
String ldisplayname = displayName.substring(0, displayName.length()-2);
player.setDisplayName(displayName);
if(ldisplayname.length()<=16)
- player.setPlayerListName(ldisplayname);
+ try{ player.setPlayerListName(ldisplayname); } catch(IllegalArgumentException ex) { ; }
ChatHandler ch = plugin.getChathandler();
ChatMode cm = ch.getPlayerChatMode(player);
@@ -409,7 +414,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
String ldisplayname = displayName.substring(0, displayName.length()-2);
p.setDisplayName(displayName);
if(ldisplayname.length()<=16)
- p.setPlayerListName(ldisplayname);
+ try{ p.setPlayerListName(ldisplayname); } catch(IllegalArgumentException ex) { ; }
// p.sendMessage("Ohai thar!");
for (String m : plugin.getMOTD()) {
p.sendMessage(m);
View
20 src/com/guntherdw/bukkit/tweakcraft/Packages/CraftIRCAdminEndPoint.java
@@ -26,9 +26,6 @@
import com.guntherdw.bukkit.tweakcraft.Chat.Modes.AdminChat;
import com.guntherdw.bukkit.tweakcraft.Exceptions.ChatModeException;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.World;
-import org.bukkit.entity.Player;
import java.util.List;
@@ -69,20 +66,9 @@ public void messageIn(RelayedMessage relayedMessage) {
if(event.equals("chat") || event.equals("action")) {
String pname = relayedMessage.getField("sender");
if(pname!=null) {
- Player p = plugin.getServer().getPlayer(pname);
- OfflinePlayer op = null;
- boolean offline = p==null;
- if(offline) {
- op = plugin.getServer().getOfflinePlayer(pname);
- }
-
- boolean found = p!=null || op!=null;
- if(found) {
- World w = offline?plugin.getServer().getWorlds().get(0):p.getWorld();
- String name = offline?op.getName():p.getName();
- relayedMessage.setField("prefix", plugin.getPermissions().getResolver().getUserPrefix(w.getName(), name));
- relayedMessage.setField("suffix", plugin.getPermissions().getResolver().getUserSuffix(w.getName(), name));
- }
+ 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
10 src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java
@@ -18,6 +18,7 @@
package com.guntherdw.bukkit.tweakcraft.Packages;
+import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
@@ -44,8 +45,17 @@ public String getNick() {
public void setNick(String nick) {
this.nick = nick;
}
+
+ public Player getBukkitPlayerSafe() {
+ return bukkitPlayer;
+ }
public Player getBukkitPlayer() {
+ if(this.bukkitPlayer == null) {
+ Player p = Bukkit.getPlayerExact(player);
+ if(p!=null) bukkitPlayer=p;
+ }
+
return bukkitPlayer;
}
View
2 src/com/guntherdw/bukkit/tweakcraft/Tools/Permissions/Permissions.java
@@ -28,7 +28,7 @@
public abstract String getUserPrefix(String player);
public String getUserPrefix(String world, Player player)
- {return getPrimaryUserGroup(world, player.getName());}
+ {return getUserPrefix(world, player.getName());}
public abstract String getUserPrefix(String world, String player);
View
23 src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java
@@ -139,9 +139,13 @@ public void sendCUIChatMode(Player player) {
player.sendRawMessage(CUIPattern+"["+cm.getPrefix()+ChatColor.WHITE+"]");
}
}
-
+
public LocalPlayer wrapPlayer(Player player) {
- return wrapPlayer(player.getName());
+ LocalPlayer p = this.wrapPlayer(player.getName());
+ if(p.getBukkitPlayerSafe()==null)
+ p.setBukkitPlayer(player);
+
+ return p;
}
public LocalPlayer wrapPlayer(String player) {
@@ -311,6 +315,20 @@ 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);
+ }
public List<Player> findPlayerasPlayerList(String partOfName) {
// Go for the nicks first!
@@ -350,6 +368,7 @@ private void registerEvents() {
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_RESPAWN, 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);
getServer().getPluginManager().registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.CHUNK_UNLOAD, worldListener , Priority.Normal, this);
View
12 src/com/guntherdw/bukkit/tweakcraft/Util/TeleportHistory.java
@@ -138,11 +138,12 @@ public void addHistory(String playername, Location loc) {
int siz = locmap.size();
int pos = siz-getOffset(playername)+1;
-
- locmap.removeAll(locmap.subList(pos, siz));
+ /* List<Location> toRemove = */ locmap.subList(pos, siz).clear();
+ // locmap.en
+ // locmap.removeAll(toRemove);
setHistoryOffset(playername, null);
}
- if(!locmap.get(locmap.size()-1).equals(loc)) locmap.add(loc);
+ if(locmap.size()>0&&!locmap.get(locmap.size()-1).equals(loc)) locmap.add(loc);
} else {
locmap = new ArrayList<Location>();
locmap.add(loc);
@@ -161,7 +162,10 @@ public void clearFuture(String playername) {
plugin.getLogger().info("[TweakcraftUtils] Clearing TPBack future for player "+playername+"!");
if(historymap.containsKey(playername) && historyoffset.containsKey(playername)) {
List<Location> loclist = historymap.get(playername);
- loclist.removeAll(loclist.subList(loclist.size()-getOffset(playername), loclist.size()));
+ int size = loclist.size();
+ // loclist.removeAll();
+ /* List<Location> toRemove = */ loclist.subList(size - getOffset(playername), size).clear();
+ /* loclist.removeAll(toRemove); */
historymap.put(playername, loclist);
setHistoryOffset(playername, null);
}

0 comments on commit f77e052

Please sign in to comment.
Something went wrong with that request. Please try again.