Permalink
Browse files

Working on LocalPlayer some more, it's going to be part of a lot more…

… in the near future,

Added some more info to /tc world info <world>
Fixed some old code in /who
Added a GameMode option to the worldmanager
Extrapolated PermissionsResolver to individual classes per permissions plugin
  • Loading branch information...
1 parent 2bd023a commit 6f49b65f3ca0c40ce451484a57972e572b6f3f33 @GuntherDW committed Oct 28, 2011
Showing with 633 additions and 232 deletions.
  1. +1 −1 plugin.yml
  2. +3 −16 src/com/guntherdw/bukkit/tweakcraft/Chat/AntiSpam.java
  3. +2 −2 src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java
  4. +12 −0 src/com/guntherdw/bukkit/tweakcraft/Commands/Admin/CommandTC.java
  5. +17 −15 src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandWho.java
  6. +1 −1 src/com/guntherdw/bukkit/tweakcraft/Commands/General/CommandBroadcast.java
  7. +3 −3 src/com/guntherdw/bukkit/tweakcraft/Commands/General/CommandWhois.java
  8. +3 −3 src/com/guntherdw/bukkit/tweakcraft/Commands/Teleportation/CommandTPBack.java
  9. +4 −4 src/com/guntherdw/bukkit/tweakcraft/Configuration/ConfigurationHandler.java
  10. +2 −2 src/com/guntherdw/bukkit/tweakcraft/DataSources/PersistenceClass/{ChatGroup.java → ChatChannel.java}
  11. +4 −0 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java
  12. +2 −2 src/com/guntherdw/bukkit/tweakcraft/Packages/CraftIRCAdminEndPoint.java
  13. +21 −0 src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java
  14. +74 −0 src/com/guntherdw/bukkit/tweakcraft/Tools/Permissions/BukkitPerms.java
  15. +89 −0 src/com/guntherdw/bukkit/tweakcraft/Tools/Permissions/NijiPerms.java
  16. +51 −0 src/com/guntherdw/bukkit/tweakcraft/Tools/Permissions/Permissions.java
  17. +91 −0 src/com/guntherdw/bukkit/tweakcraft/Tools/Permissions/PermsEx.java
  18. +78 −0 src/com/guntherdw/bukkit/tweakcraft/Tools/Permissions/WEPIFPerms.java
  19. +42 −134 src/com/guntherdw/bukkit/tweakcraft/Tools/PermissionsResolver.java
  20. +36 −5 src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java
  21. +44 −14 src/com/guntherdw/bukkit/tweakcraft/Worlds/TweakWorld.java
  22. +19 −1 src/com/guntherdw/bukkit/tweakcraft/Worlds/WorldManager.java
  23. +34 −29 src/com/guntherdw/bukkit/tweakcraft/Worlds/iWorld.java
View
@@ -1,6 +1,6 @@
name: TweakcraftUtils
main: com.guntherdw.bukkit.tweakcraft.TweakcraftUtils
-version: 2.2.6
+version: 2.2.7-git
authors:
- GuntherDW
- Meaglin
@@ -46,13 +46,10 @@ public AntiSpam(ChatHandler instance, ConfigurationHandler config) {
public int checkSpam(Player player, String message) {
if(!ch.getTCUtilsInstance().check(player, "spam")) {
- LocalPlayer lp = null;
+
+ LocalPlayer lp = ch.getTCUtilsInstance().wrapPlayer(player);
+
String playername = player.getName().toLowerCase();
- if(!playerlist.containsKey(playername)) {
- lp = new LocalPlayer(playername);
- } else {
- lp = playerlist.get(playername);
- }
long currenttime = System.currentTimeMillis();
int oldspamcounter = lp.getSpamcounter();
@@ -62,16 +59,6 @@ public int checkSpam(Player player, String message) {
lp.setSpamcounter(0);
}
lp.setLastmessagetime(currenttime);
-
-
- /* if(lp.getSpamcounter()!=0) {
- this.playerlist.put(playername, lp);
- } else {
- if(this.playerlist.containsKey(playername))
- this.playerlist.remove(playername);
- } */
-
- this.playerlist.put(playername, lp);
return lp.getSpamcounter();
}
@@ -88,8 +88,8 @@ public boolean sendMessage(CommandSender sender, String message) {
Player p = (Player) sender;
// World w = p.getWorld();
rmsg.setField("world", p.getWorld().getName());
- rmsg.setField("prefix", plugin.getPermissionsResolver().getUserPrefix(p.getWorld().getName(), p));
- rmsg.setField("suffix", plugin.getPermissionsResolver().getUserSuffix(p.getWorld().getName(), p));
+ rmsg.setField("prefix", plugin.getPermissions().getResolver().getUserPrefix(p.getWorld().getName(), p));
+ rmsg.setField("suffix", plugin.getPermissions().getResolver().getUserSuffix(p.getWorld().getName(), p));
}
rmsg.post();
}
@@ -29,6 +29,7 @@
import com.guntherdw.bukkit.tweakcraft.Worlds.TweakWorld;
import com.guntherdw.bukkit.tweakcraft.Worlds.iWorld;
import org.bukkit.ChatColor;
+import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -197,6 +198,9 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
boolean animals = tcworld?iw.getAllowAnimals():bw.getAllowAnimals();
boolean pvp = tcworld?iw.getPVP():bw.getPVP();
int amountofplayers = tcworld?iw.getBukkitWorld().getPlayers().size():bw.getPlayers().size();
+ boolean customChunkGen = tcworld?iw.getChunkGen()!=null:bw.getGenerator()!=null;
+ boolean tooldura = tcworld?iw.isDurabilityEnabled():bw.getToolDurability();
+ GameMode gm = tcworld?iw.getGameMode():null;
String players = "";
if(amountofplayers<5) {
List<Player> ps = tcworld?iw.getBukkitWorld().getPlayers():bw.getPlayers();
@@ -213,6 +217,14 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
sender.sendMessage(ChatColor.RED+"PVP: "+(pvp?ChatColor.GREEN+"enabled":ChatColor.RED+"disabled"));
sender.sendMessage(ChatColor.RED+"ENV: "+wenv);
sender.sendMessage(ChatColor.RED+"PLAYERS: "+amountofplayers + (players.equals("")?"":(" ("+players+ChatColor.RED+")")));
+ sender.sendMessage(ChatColor.RED+"TOOL DURABILITY: "+(tooldura?ChatColor.GREEN+"enabled":ChatColor.RED+"disabled"));
+ if(gm!=null)
+ sender.sendMessage(ChatColor.RED+"GAMEMODE: "+gm.toString().toLowerCase());
+ if(customChunkGen) {
+ String ChunkGen = tcworld?iw.getChunkGen():bw.getGenerator().getClass().getName();
+ sender.sendMessage(ChatColor.RED+"CHUNKGEN: "+ChunkGen);
+ }
+
}
} else {
@@ -22,6 +22,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.Tools.ArgumentParser;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import org.bukkit.ChatColor;
@@ -47,14 +48,14 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
String world = ap.getString("w", null);
String[] args = ap.getUnusedArgs();
World w = null;
-
+
if(world!=null) {
w=plugin.getServer().getWorld(world);
if(w==null) throw new CommandUsageException("World not found!");
}
-
+
List<Player> list = null;
-
+
if(w==null) list = Arrays.asList(plugin.getServer().getOnlinePlayers());
else list = w.getPlayers();
Integer amountofinvis = 0;
@@ -65,9 +66,9 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
}
boolean hasperm;
if(sender instanceof Player)
- hasperm = plugin.check((Player)sender, "tpinvis");
- else
- hasperm = true;
+ hasperm = plugin.check((Player)sender, "tpinvis");
+ else
+ hasperm = true;
String msg = ChatColor.LIGHT_PURPLE + "Player list (" + (w==null? (list.size()-amountofinvis) + "/" + plugin.getServer().getMaxPlayers() : ChatColor.GREEN+w.getName() + ChatColor.LIGHT_PURPLE) + "): ";
if(amountofinvis>0) {
@@ -84,12 +85,13 @@ public int compare(Player p1, Player p2) {
sender.sendMessage(msg);
msg = " ";
boolean check;
-
+
for (Player p : list) {
+ LocalPlayer lp = plugin.wrapPlayer(p);
toadd = "";
check = plugin.getPlayerListener().getInvisplayers().contains(p.getName());
- if (!(sender instanceof Player)) { // console won't show gold colors? shame! // THIS HAS BEEN FIXED LONG AGO!
+ /* if (!(sender instanceof Player)) { // console won't show gold colors? shame! // THIS HAS BEEN FIXED LONG AGO!
if(check)
toadd = ChatColor.AQUA+"[";
@@ -99,14 +101,14 @@ public int compare(Player p1, Player p2) {
toadd += ChatColor.AQUA+"]";
toadd+=ChatColor.WHITE+", ";
- } else {
- if(check && hasperm)
- {
- toadd = ChatColor.AQUA+"["+p.getDisplayName() + ChatColor.AQUA + "]"+ChatColor.WHITE+", ";
- } else if(!check) {
- toadd = p.getDisplayName() + ChatColor.WHITE + ", ";
- }
+ } else { */
+ if(check && hasperm)
+ {
+ toadd = ChatColor.AQUA+"["+p.getDisplayName() + ChatColor.AQUA + "]"+ (lp.isAfk()?ChatColor.RED+" [AFK]":"") +ChatColor.WHITE+", ";
+ } else if(!check) {
+ toadd = p.getDisplayName() + (lp.isAfk()?ChatColor.RED+" [AFK]":"") + ChatColor.WHITE + ", ";
}
+ // }
msg += toadd;
}
if (!msg.trim().isEmpty()) {
@@ -53,7 +53,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
groups = grouparg.split(",");
for(String gr : groups) {
for(Player p : plugin.getServer().getOnlinePlayers()) {
- if(plugin.getPermissionsResolver().inSingleGroup("world", gr, p)) {
+ if(plugin.getPermissions().getResolver().inSingleGroup("world", gr, p)) {
if(!recipients.contains(p))
recipients.add(p);
}
@@ -62,7 +62,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
boolean online = (who!=null);
if(who==null) { // Is it an offline player? Check permissions
- if(plugin.getPermissionsResolver()!=null) {
+ if(plugin.getPermissions().getResolver()!=null) {
// Check for nicks
// String pname = args[0];
OfflinePlayer offlineplayer = plugin.getServer().getOfflinePlayer(nick_origplayer!=null?nick_origplayer:args[0]);
@@ -73,7 +73,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
wname = defworld.getName();
}
- groups = plugin.getPermissionsResolver().getPrimaryUserGroup(wname, pname);
+ groups = plugin.getPermissions().getResolver().getPrimaryUserGroup(wname, pname);
if(groups!=null) {
String n = plugin.getNickWithColors(pname);
if(n!=null) {
@@ -94,7 +94,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
wname = defworld.getName();
}
- groups = plugin.getPermissionsResolver().getPrimaryUserGroup(wname, playername);
+ groups = plugin.getPermissions().getResolver().getPrimaryUserGroup(wname, playername);
// Check for a nick!
String n = plugin.getNickWithColors(playername);
if(n!=null) {
@@ -64,14 +64,14 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
boolean success = player.teleport(back);
if(success) {
- Integer remaining = plugin.getTelehistory().getRemaining(player.getName());
+ /* Integer remaining = plugin.getTelehistory().getRemaining(player.getName());
String rem = "";
if(remaining == null || remaining == 0) {
rem = "Origin! No TPBack lines left!";
} else {
rem = remaining+" TPBack lines left!";
- }
- player.sendMessage(ChatColor.GOLD+"Amount of TPBack lines left : "+rem);
+ } */
+ // player.sendMessage(ChatColor.GOLD+"Amount of TPBack lines left : "+rem);
plugin.getTelehistory().removeLast(player.getName());
} else {
player.sendMessage(ChatColor.RED+"tpback failure, tpback line NOT removed!");
@@ -19,7 +19,6 @@
package com.guntherdw.bukkit.tweakcraft.Configuration;
import com.guntherdw.bukkit.tweakcraft.Packages.LockdownLocation;
-import com.guntherdw.bukkit.tweakcraft.Tools.PermissionsResolver;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -77,7 +76,7 @@
public boolean enablemod_InfDura = false;
public boolean enableExperienceOrbsHalt = false;
- public PermissionsResolver.PermissionResolvingMode permissoinsResolvingMode = null;
+ // public PermissionsResolver.PermissionResolvingMode permissoinsResolvingMode = null;
public boolean enableRespawnHook = false;
public boolean enableRespawnHeal = false;
@@ -165,7 +164,8 @@ public void reloadConfig() {
String presolver = globalconfig.getString("Permissions.resolver", null);
if(presolver==null) presolver = "permissions";
- if(presolver.equals("permissions")) {
+ /* This is done fully automatic now! */
+ /* if(presolver.equals("permissions")) {
permissoinsResolvingMode = PermissionsResolver.PermissionResolvingMode.NIJIPERMS;
} else if(presolver.equals("permissionsex")) {
permissoinsResolvingMode = PermissionsResolver.PermissionResolvingMode.PERMISSIONSEX;
@@ -176,7 +176,7 @@ public void reloadConfig() {
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);
@@ -30,8 +30,8 @@
* @author GuntherDW
*/
@Entity()
-@Table(name="tcutils_chatgroup")
-public class ChatGroup {
+@Table(name="tcutils_chatchannel")
+public class ChatChannel {
@Id
@NotNull
@@ -385,6 +385,10 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You don't have access to this world!");
}
+ iWorld tw = plugin.getworldManager().getWorld(event.getTo().getWorld().getName(), true);
+ if(tw!=null && !tw.getGameMode().equals(player.getGameMode())) {
+ player.setGameMode(tw.getGameMode());
+ }
}
// if(event)
}
@@ -80,8 +80,8 @@ public void messageIn(RelayedMessage relayedMessage) {
if(found) {
World w = offline?plugin.getServer().getWorlds().get(0):p.getWorld();
String name = offline?op.getName():p.getName();
- relayedMessage.setField("prefix", plugin.getPermissionsResolver().getUserPrefix(w.getName(), name));
- relayedMessage.setField("suffix", plugin.getPermissionsResolver().getUserSuffix(w.getName(), name));
+ relayedMessage.setField("prefix", plugin.getPermissions().getResolver().getUserPrefix(w.getName(), name));
+ relayedMessage.setField("suffix", plugin.getPermissions().getResolver().getUserSuffix(w.getName(), name));
}
}
ac.broadcastMessage(relayedMessage.getMessage(this));
@@ -18,15 +18,36 @@
package com.guntherdw.bukkit.tweakcraft.Packages;
+import org.bukkit.entity.Player;
+
/**
* @author GuntherDW
*/
public class LocalPlayer {
private String player;
+ private Player bukkitPlayer;
+ private boolean afk;
private int spamcounter;
private long lastmessagetime;
+
+ public Player getBukkitPlayer() {
+ return bukkitPlayer;
+ }
+
+ public void setBukkitPlayer(Player bukkitPlayer) {
+ this.bukkitPlayer = bukkitPlayer;
+ }
+
+ public boolean isAfk() {
+ return afk;
+ }
+
+ public void setAfk(boolean afk) {
+ this.afk = afk;
+ }
+
public long getLastmessagetime() {
return lastmessagetime;
}
@@ -0,0 +1,74 @@
+/*
+ * 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.Tools.Permissions;
+
+import com.guntherdw.bukkit.tweakcraft.Tools.PermissionsResolver;
+import org.bukkit.entity.Player;
+
+/**
+ * @author GuntherDW
+ */
+public class BukkitPerms extends Permissions {
+
+ private PermissionsResolver permsResolver;
+
+ public BukkitPerms(PermissionsResolver instance) {
+ this.permsResolver = instance;
+ }
+
+ @Override
+ public String getUserPrefix(String player) {
+ return "§f"; // Not really implemented is it?
+ }
+
+ @Override
+ public String getUserPrefix(String world, String player) {
+ return "§f"; // Not really implemented is it?
+ }
+
+ @Override
+ public String getPrimaryUserGroup(String world, String player) {
+ return null;
+ }
+
+ @Override
+ public String getUserSuffix(String world, String player) {
+ return "§f"; // Not really implemented is it?
+ }
+
+ @Override
+ public boolean inGroup(String group, Player player) {
+ return false;
+ }
+
+ @Override
+ public boolean inGroup(String world, String group, Player player) {
+ return false;
+ }
+
+ @Override
+ public boolean inSingleGroup(String world, String group, Player player) {
+ return false;
+ }
+
+ @Override
+ public boolean hasPermission(String world, Player player, String permissionbit) {
+ return player.hasPermission(permissionbit);
+ }
+}
Oops, something went wrong.

0 comments on commit 6f49b65

Please sign in to comment.