Permalink
Browse files

Optimising a couple classes,

Added the ability to see the difficulty of a world,
Fixed /spawnmob,
Removed /b as an alias to /broadcast, VoxelSniper isn't properly coded to cope with this,
Fixed maxheight of 128?
Added the ability to allow certain players to fly in certain worlds,
Added WorldEdit ItemDB support,
Tweaked the tamertool a bit,
  • Loading branch information...
1 parent 149e2f7 commit 9b845cddc0da773d48ff90cf43f9fcaff402c694 @GuntherDW committed Jul 1, 2012
View
@@ -91,7 +91,7 @@ commands:
broadcast:
description: Broadcasts said message to the server
usage: /<command> <message>
- aliases: [ 'b', 'broa' ]
+ aliases: [ 'broa' ]
tpmob:
description: Teleports a mob to you
usage: /<command> <mobid>
@@ -22,8 +22,6 @@
import com.guntherdw.bukkit.tweakcraft.Chat.ChatMode;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import com.sk89q.worldedit.Vector;
-import com.sk89q.worldguard.LocalPlayer;
-import com.sk89q.worldguard.bukkit.BukkitPlayer;
import com.sk89q.worldguard.protection.GlobalRegionManager;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.ChatColor;
@@ -83,7 +81,7 @@ public boolean sendMessage(CommandSender sender, String message) {
RegionManager rm = gm.get(player.getWorld());
Location loc = player.getLocation().clone();
Vector vec = new Vector(loc.getX(), loc.getY(), loc.getZ());
- LocalPlayer localplayer = new BukkitPlayer(plugin.getWorldGuard(), player);
+ // LocalPlayer localplayer = new BukkitPlayer(plugin.getWorldGuard(), player);
// ApplicableRegionSet regionset = rm.getApplicableRegions(vec);
regionIds = rm.getApplicableRegionsIDs(vec);
Vector pvec = null;
@@ -614,7 +614,7 @@ public boolean tweakcraft(CommandSender sender, String command, String[] args)
sender.sendMessage(ChatColor.RED+"MONSTERS: "+(monsters?ChatColor.GREEN+"enabled":ChatColor.RED+"disabled"));
sender.sendMessage(ChatColor.RED+"PVP: "+(pvp?ChatColor.GREEN+"enabled":ChatColor.RED+"disabled"));
sender.sendMessage(ChatColor.RED+"ENV: "+wenv);
- sender.sendMessage(ChatColor.RED+"DIFFICULITY: "+difficulty.name().toLowerCase());
+ sender.sendMessage(ChatColor.RED+"DIFFICULTY: "+difficulty.name().toLowerCase());
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)
@@ -412,8 +412,7 @@ public boolean item(CommandSender sender, String command, String[] realargs)
int dataval = ap.getInteger("dat", -1);
String[] args = ap.getUnusedArgs();
- if (args.length > 0) // just the item!
- {
+ if (args.length > 0) { // just the item!
String[] split = args[0].split(":");
if (split.length > 1) {
try {
@@ -446,19 +445,6 @@ public boolean item(CommandSender sender, String command, String[] realargs)
itemAmount = 64;
}
- /* if (args.length > 2) { // set Receiver
- receiver = plugin.getServer().getPlayer(plugin.findPlayer(args[2]));
- if (receiver == null) {
- throw new CommandUsageException("Can't find the other player!");
- }
- } else {
- if (sender instanceof Player)
- receiver = (Player) sender;
- else
- throw new CommandUsageException("If you're a console you have to specify the receiver!");
-
- } */
-
if (dmgval > -1 && dmgval < 256) {
itemDmg = (byte) dmgval;
}
@@ -1010,8 +996,7 @@ public boolean spawnMob(CommandSender sender, String command, String[] realargs)
LivingEntity lent = null;
List<EntityType> riders = null;
- if (args.length > 0) // only a mobname!
- {
+ if (args.length > 0) { // only a mobname!
mobName = "";
amount = 1;
if (args[0].length() > 2)
@@ -1069,7 +1054,11 @@ public boolean spawnMob(CommandSender sender, String command, String[] realargs)
if (type != null) {
LivingEntity rid = null;
for (int x = 0; x < amount; x++) {
- lent = victimplayer.getWorld().spawnCreature(loc, type);
+
+ // lent = victimplayer.getWorld().spawnCreature(loc, type);
+
+ lent = (LivingEntity) victimplayer.getWorld().spawnEntity(loc, type);
+
if (health > 0)
lent.setHealth(health);
@@ -1135,7 +1124,7 @@ public boolean spawnMob(CommandSender sender, String command, String[] realargs)
if (riders != null && riders.size() != 0) {
for (EntityType t : riders) {
- rid = victimplayer.getWorld().spawnCreature(loc, t);
+ rid = (LivingEntity) victimplayer.getWorld().spawnEntity(loc, t);
if (lent != null) lent.setPassenger(rid);
lent = rid; // This makes the currently added mob the new "to-ride-along" mob
}
@@ -130,7 +130,7 @@ public boolean setAFK(CommandSender sender, String command, String[] args)
}
@aCommand(
- aliases = { "broadcast", "b", "broa" },
+ aliases = { "broadcast", "broa" },
permissionBase = "broadcast",
description = "Broadcasts said message to the server",
section = "general"
@@ -405,8 +405,9 @@ public boolean tpBack(CommandSender sender, String command, String[] args)
} else {
player.sendMessage(ChatColor.GOLD + "Teleporting you back to your previous position!");
- if (back.getY() == 130) {
- player.sendMessage(ChatColor.GOLD + "Sending you to Y:130 because you were either too high or too low!");
+ int maxHeightplus2 = back.getWorld().getMaxHeight() + 2;
+ if (back.getY() == maxHeightplus2) {
+ player.sendMessage(ChatColor.GOLD + "Sending you to Y:"+maxHeightplus2+" because you were either too high or too low!");
}
boolean success = player.teleport(back);
@@ -475,8 +476,9 @@ public boolean tpForward(CommandSender sender, String command, String[] args)
player.sendMessage(ChatColor.GOLD + "You don't have any future issues yet/left!");
} else {
player.sendMessage(ChatColor.GOLD + "Teleporting you back to your future position!");
- if (back.getY() == 130) {
- player.sendMessage(ChatColor.GOLD + "Sending you to Y:130 because you were either too high or too low!");
+ int maxHeightplus2 = back.getWorld().getMaxHeight() + 2;
+ if (back.getY() == maxHeightplus2) {
+ player.sendMessage(ChatColor.GOLD + "Sending you to Y:"+maxHeightplus2+" because you were either too high or too low!");
}
boolean success = player.teleport(back);
@@ -52,6 +52,12 @@ public void onEntityTarget(EntityTargetEvent event) {
|| event.isCancelled() || !(event.getTarget() instanceof Player)) return;
LocalPlayer lp = plugin.wrapPlayer((Player) event.getTarget());
+
+ if(lp.isInvisible()) {
+ event.setCancelled(true);
+ return;
+ }
+
if (event.getReason().equals(EntityTargetEvent.TargetReason.CLOSEST_PLAYER)
|| event.getReason().equals(EntityTargetEvent.TargetReason.RANDOM_TARGET)) {
if (lp.isAfk()) event.setCancelled(true);
@@ -545,6 +545,11 @@ public void onPlayerJoin(PlayerJoinEvent event) {
}
plugin.sendmod_InfDuraHandshake(p);
}
+
+ iWorld iw = plugin.getworldManager().getWorld(p.getWorld().getName());
+
+ if(lp.isAllowedFlight() || (iw!=null && iw.isAllowFlight()))
+ p.setAllowFlight(true);
}
@EventHandler(priority = EventPriority.NORMAL)
@@ -1043,12 +1048,21 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
- if (!plugin.getConfigHandler().enableWorldMOTD) return;
Player player = event.getPlayer();
+ LocalPlayer lp = plugin.wrapPlayer(player);
+
WorldManager wm = plugin.getworldManager();
iWorld world = wm.getWorld(player.getWorld().getName(), true);
- if (world != null && world.hasWorldMOTD()) {
+
+ if(world == null || world.isDurabilityEnabled())
+ player.setAllowFlight(false);
+ else if(lp.isAllowedFlight() || world.isAllowFlight() || world.getGameMode() == GameMode.CREATIVE)
+ player.setAllowFlight(true);
+ else if((!world.isAllowFlight() && !lp.isAllowedFlight()))
+ player.setAllowFlight(false);
+
+ if (plugin.getConfigHandler().enableWorldMOTD && (world != null && world.hasWorldMOTD())) {
for (String line : world.getMOTD())
player.sendMessage(line);
}
@@ -19,6 +19,8 @@
package com.guntherdw.bukkit.tweakcraft.Packages;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
+import com.sk89q.worldedit.blocks.ItemType;
+import org.bukkit.Bukkit;
import java.io.*;
import java.util.HashMap;
@@ -30,7 +32,7 @@
public class ItemDB {
private TweakcraftUtils plugin;
- private Map<String, com.guntherdw.bukkit.tweakcraft.Packages.Item> itemmap;
+ private Map<String, Item> itemmap;
public ItemDB(TweakcraftUtils instance) {
this.plugin = instance;
@@ -72,6 +74,16 @@ public Item getItem(String name) {
if (itemmap.containsKey(name)) {
return itemmap.get(name);
} else {
+ // try WorldEdit first!
+ if(plugin.getWorldEdit()!=null) {
+ ItemType it = ItemType.lookup(name, true);
+ if(it!=null) {
+ Item item = new Item(it.getID(), (byte) 0, 64);
+ // Let's add that to the cache, for performance reasons
+ itemmap.put(name, item);
+ return item;
+ }
+ }
return null;
}
}
@@ -41,12 +41,23 @@
private boolean invisiblePickup = false;
private String replyTo = null;
private boolean tntArrow = false;
+ private boolean allowedFlight = false;
private String capeURL = null;
public boolean isInvisible() {
return this.invisible;
}
+ public boolean isAllowedFlight() {
+ return allowedFlight;
+ }
+
+ public void setAllowedFlight(boolean hasFlight) {
+ this.allowedFlight = hasFlight;
+ if(getBukkitPlayer()!=null)
+ getBukkitPlayer().setAllowFlight(hasFlight);
+ }
+
public void setInvisible(boolean state) {
this.invisible = state;
}
@@ -90,10 +90,19 @@ public void getOwner(Player player, Tameable tameable) {
player.sendMessage(ChatColor.AQUA + "This tameable is "+ChatColor.RED+"angry"+ChatColor.AQUA+"!");
LivingEntity le = wolf.getTarget();
String target = "";
- if(le instanceof Player)
- target = ((Player)le).getDisplayName();
- else
- target = "Animal";
+ if(le instanceof OfflinePlayer)
+ if(((OfflinePlayer) le).isOnline())
+ target = ((Player)le).getDisplayName();
+ else
+ target = ((OfflinePlayer) le).getName();
+ else {
+ String extraInfo = "";
+ if ( le != null ) {
+ EntityType et = le.getType();
+ extraInfo = et.getName();
+ }
+ target = "Animal "+extraInfo;// +le!=null?" ("+(et.getName())+")":"";
+ }
player.sendMessage(ChatColor.AQUA + "Target : "+target);
}
}
@@ -169,7 +169,7 @@ public void sendCUIChatMode(Player player) {
public LocalPlayer wrapPlayer(Player player) {
LocalPlayer p = this.wrapPlayer(player.getName());
- if (p.getBukkitPlayer() == null)
+ if (p.getBukkitPlayer() == null || p.getBukkitPlayer() != player)
p.setBukkitPlayer(player);
return p;
@@ -649,6 +649,7 @@ public void onEnable() {
this.cuiPlayers = new HashSet<Player>();
this.mod_InfDuraplayers = new HashSet<Player>();
+ this.setupWorldEdit();
this.setupWorldGuard();
this.setupCraftIRC();
this.setupZones();
@@ -50,10 +50,12 @@
private String chunkGenClass = null;
private ChunkGenerator chunkgen = null;
private org.bukkit.World.Environment environment;
+ private org.bukkit.WorldType worldType = null;
private WorldManager wm;
private boolean pvp = true;
private int viewdistance = 10;
private GameMode gamemode = null;
+ private boolean allowFlight = false;
private String[] motd;
public TweakWorld(WorldManager wm, String foldername, org.bukkit.World.Environment env, boolean enabled) {
@@ -155,10 +157,34 @@ public void setSeed(long seed, boolean netherseed) {
else this.seed = seed;
}
+ public Long getNetherseed() {
+ return netherseed;
+ }
+
+ public void setNetherseed(Long netherseed) {
+ this.netherseed = netherseed;
+ }
+
+ public Long getEndseed() {
+ return endseed;
+ }
+
+ public void setEndseed(Long endseed) {
+ this.endseed = endseed;
+ }
+
public ChunkGenerator getChunkGen() {
return chunkgen;
}
+ public void setWorldType(WorldType type) {
+ this.worldType = type;
+ }
+
+ public WorldType getWorldType() {
+ return this.worldType;
+ }
+
public void setChunkGen(String chunkGen) {
resolvePluginChunkGenerator(chunkGen);
}
@@ -231,9 +257,9 @@ else if (chunkGenClass != null) {
ChunkGenerator cg = (ChunkGenerator) c;
if (c instanceof FlatGen) {
FlatGen fg = (FlatGen) cg;
- int mh = wm.getPlugin().getConfig().getInt("worlds.extraworlds." + worldName + ".flatGen.mapHeight", 12);
- byte toplayer = (byte) wm.getPlugin().getConfig().getInt("worlds.extraworlds." + worldName + ".flatGen.toplayer", Material.GRASS.getId());
- byte normal = (byte) wm.getPlugin().getConfig().getInt("worlds.extraworlds." + worldName + ".flatGen.normal", Material.DIRT.getId());
+ int mh = wm.getPlugin().getConfigHandler().getGlobalconfig().getInt("worlds.extraworlds." + worldName + ".flatGen.mapHeight", 12);
+ byte toplayer = (byte) wm.getPlugin().getConfigHandler().getGlobalconfig().getInt("worlds.extraworlds." + worldName + ".flatGen.toplayer", Material.GRASS.getId());
+ byte normal = (byte) wm.getPlugin().getConfigHandler().getGlobalconfig().getInt("worlds.extraworlds." + worldName + ".flatGen.normal", Material.DIRT.getId());
fg.setmapHeight(mh);
fg.setNormal(normal);
fg.setToplayer(toplayer);
@@ -266,16 +292,14 @@ else if (chunkGenClass != null) {
if (seed != null)
worldCreator.seed(seed);
+ WorldType type = getWorldType();
+ if(type!=null)
+ worldCreator.type(type);
+
if (enabled) {
worldCreator.environment(env);
- if(worldCreator.generator() instanceof FlatGen) {
- this.wm.getPlugin().getLogger().info("[TweakcraftUtils] World " + worldName + " is using FlatGen so setting WorldType to FLAT!");
- worldCreator.type(WorldType.FLAT);
- }
-
world = worldCreator.createWorld();
-
world.setKeepSpawnInMemory(this.getSpawnChunksActive());
world.setPVP(pvp);
}
@@ -306,6 +330,14 @@ public void setSpawnChunksActive(boolean state) {
this.keepspawnactive = state;
}
+ public boolean isAllowFlight() {
+ return allowFlight;
+ }
+
+ public void setAllowFlight(boolean allowFlight) {
+ this.allowFlight = allowFlight;
+ }
+
public boolean getSpawnChunksActive() {
return this.keepspawnactive;
}
@@ -346,7 +378,7 @@ public void addNether() {
this.nether_enabled = true;
this.nether = nw;
}
-
+
public void addTheEnd() {
if(!isEnabled()) return;
WorldCreator wc = new WorldCreator(this.world.getName() + "_the_end");
@@ -357,7 +389,7 @@ public void addTheEnd() {
}
endw.setSpawnFlags(this.allowmonsters, this.allowanimals);
endw.setToolDurability(this.tooldurability);
-
+
this.the_end_enabled = true;
this.the_end = endw;
}
Oops, something went wrong.

0 comments on commit 9b845cd

Please sign in to comment.