Permalink
Browse files

Added world option for /who, Modified /listworlds to show the player …

…amount in front of the worldname,

Added TweakTravelAgent, isn't in use right now though.
Modified ArgumentParser, added a function that outputs the "normal" args and the unused ones.
Added a searchwidth option per-world for nether portals.
Added listname colours
  • Loading branch information...
1 parent a57fc81 commit 92738e17b2098fd34798f08485ef64cb2ab696f7 @GuntherDW committed Sep 30, 2011
View
8 src/com/guntherdw/bukkit/tweakcraft/Commands/Admin/CommandTC.java
@@ -18,9 +18,8 @@
package com.guntherdw.bukkit.tweakcraft.Commands.Admin;
-import com.guntherdw.bukkit.tweakcraft.Chat.ChatMode;
-import com.guntherdw.bukkit.tweakcraft.DataSources.Ban.BanHandler;
import com.guntherdw.bukkit.tweakcraft.Commands.iCommand;
+import com.guntherdw.bukkit.tweakcraft.DataSources.Ban.BanHandler;
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandSenderException;
import com.guntherdw.bukkit.tweakcraft.Exceptions.CommandUsageException;
@@ -65,7 +64,10 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
for (Player p : plugin.getServer().getOnlinePlayers()) {
String name = p.getName();
// p.setDisplayName(plugin.getPlayerColor(name, false) + name + ChatColor.WHITE);
- p.setDisplayName(plugin.getNickWithColors(p.getName()));
+ String displayName = plugin.getNickWithColors(p.getName());
+ p.setDisplayName(displayName);
+ if(displayName.length()<16)
+ p.setListName(displayName);
}
plugin.getPlayerListener().reloadInvisTable();
/**
View
4 src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandListWorlds.java
@@ -53,7 +53,7 @@ else if (w.getEnvironment() == World.Environment.SKYLANDS)
col = ChatColor.AQUA.toString();
else
col = ChatColor.GRAY.toString();
- player.sendMessage(col + w.getName());
+ player.sendMessage(ChatColor.LIGHT_PURPLE+ "(" + w.getPlayers().size()+") " + col + w.getName());
}
}
@@ -66,7 +66,7 @@ else if (w.getEnvironment() == World.Environment.SKYLANDS)
sender.sendMessage("Currently enabled worlds : ");
String message = "";
for (World w : plugin.getServer().getWorlds()) {
- message += w.getName() + ", ";
+ message += w.getName() + " ("+w.getPlayers().size()+"), ";
}
if (message.length() > 1)
message = message.substring(0, message.length() - 2);
View
26 src/com/guntherdw/bukkit/tweakcraft/Commands/Essentials/CommandWho.java
@@ -22,8 +22,10 @@
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.Tools.ArgumentParser;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import org.bukkit.ChatColor;
+import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -37,10 +39,24 @@
*/
public class CommandWho implements iCommand {
- public boolean executeCommand(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
+ public boolean executeCommand(CommandSender sender, String command, String[] realargs, TweakcraftUtils plugin)
throws PermissionsException, CommandSenderException, CommandUsageException {
- List<Player> list = Arrays.asList(plugin.getServer().getOnlinePlayers());
+
+ ArgumentParser ap = new ArgumentParser(realargs);
+ 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;
for(Player p : list)
{
@@ -53,7 +69,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] arg
else
hasperm = true;
- String msg = ChatColor.LIGHT_PURPLE + "Player list (" + (list.size()-amountofinvis) + "/" + plugin.getServer().getMaxPlayers() + "): ";
+ 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) {
if(hasperm)
msg += ChatColor.AQUA+" ["+list.size()+"/"+plugin.getServer().getMaxPlayers()+"]";
@@ -73,11 +89,11 @@ public int compare(Player p1, Player p2) {
toadd = "";
check = plugin.getPlayerListener().getInvisplayers().contains(p.getName());
- if (!(sender instanceof Player)) { // console won't show gold colors? shame!
+ if (!(sender instanceof Player)) { // console won't show gold colors? shame! // THIS HAS BEEN FIXED LONG AGO!
if(check)
toadd = ChatColor.AQUA+"[";
- toadd += p.getDisplayName().replace(ChatColor.GOLD.toString(), ChatColor.YELLOW.toString());
+ toadd += p.getDisplayName(); // .replace(ChatColor.GOLD.toString(), ChatColor.YELLOW.toString());
if(check)
toadd += ChatColor.AQUA+"]";
View
2 src/com/guntherdw/bukkit/tweakcraft/Commands/General/CommandBroadcast.java
@@ -62,7 +62,7 @@ public boolean executeCommand(CommandSender sender, String command, String[] rea
} else
recipients = Arrays.asList(plugin.getServer().getOnlinePlayers());
- String[] args = ap.getNormalArgs();
+ String[] args = ap.getUnusedArgs();
if (args.length < 1) {
throw new CommandUsageException("You did not specify a message!");
View
4 src/com/guntherdw/bukkit/tweakcraft/Configuration/ConfigurationHandler.java
@@ -77,7 +77,7 @@
public boolean enableRespawnHook = false;
public boolean enableRespawnHeal = false;
-
+ // public int portalSearchRadius = 128;
public boolean enableSpamControl = false;
public long spamCheckTime = 500L;
@@ -164,7 +164,7 @@ public void reloadConfig() {
this.paySaddle = plugin.getConfiguration().getBoolean("mount.paysaddle", true);
this.stopChunkUnloadBurningFurnace = plugin.getConfiguration().getBoolean("extra.stopChunkUnloadBurningFurnace", false);
this.pigRecoverSaddle = plugin.getConfiguration().getBoolean("extra.recoverPigSaddle", true);
- this.stopIgniteWorldGuard = plugin.getConfiguration().getBoolean("extra.StopGodIgnite", true);
+ this.stopIgniteWorldGuard = plugin.getConfiguration().getBoolean("extra.stopGodIgnite", false);
this.enableCUI = plugin.getConfiguration().getBoolean("extra.CUI", false);
this.enablemod_InfDura = plugin.getConfiguration().getBoolean("extra.mod_InfDura", false);
this.enableExperienceOrbsHalt = plugin.getConfiguration().getBoolean("extra.stopExperienceOrbs", false);
View
33 src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java
@@ -28,10 +28,7 @@
import com.guntherdw.bukkit.tweakcraft.Packages.Ban;
import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
import com.guntherdw.bukkit.tweakcraft.Worlds.IWorld;
-import org.bukkit.ChatColor;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.World;
+import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.*;
@@ -250,7 +247,10 @@ public void onPlayerChat(PlayerChatEvent event) {
Player player = event.getPlayer();
String message = event.getMessage();
String name = player.getName();
- player.setDisplayName(plugin.getNickWithColors(player.getName()));
+ String displayName = plugin.getNickWithColors(player.getName());
+ player.setDisplayName(displayName);
+ if(displayName.length()<16)
+ player.setListName(displayName);
ChatHandler ch = plugin.getChathandler();
ChatMode cm = ch.getPlayerChatMode(player);
@@ -361,7 +361,10 @@ public void onPlayerLogin(PlayerLoginEvent event) {
public void onPlayerJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
String name = p.getName();
- event.getPlayer().setDisplayName(plugin.getNickWithColors(name));
+ String displayName = plugin.getNickWithColors(p.getName());
+ p.setDisplayName(displayName);
+ if(displayName.length()<16)
+ p.setListName(displayName);
// p.sendMessage("Ohai thar!");
for (String m : plugin.getMOTD()) {
p.sendMessage(m);
@@ -580,11 +583,25 @@ public void onPlayerPortal(PlayerPortalEvent event) {
if(!w.isNetherEnabled()) return;
org.bukkit.Location to = event.getFrom();
- if(isnether) { to.setWorld(w.getBukkitWorld()); to.setX(to.getX()*8); to.setZ(to.getZ()*8); }
- else { to.setWorld(w.getNetherWorld()); to.setX(to.getX()/8); to.setZ(to.getZ()/8);}
+ // System.out.println("from : "+event.getFrom());
+ if(isnether) { to.setWorld(w.getBukkitWorld()); to.setX(Math.floor(to.getX()*8)); to.setZ(Math.floor(to.getZ()*8)); }
+ else { to.setWorld(w.getNetherWorld()); to.setX(Math.floor(to.getX()/8)); to.setZ(Math.floor(to.getZ()/8));}
+ // TweakWorld tw = plugin.getworldManager().getWorld()
+ TravelAgent agent = event.getPortalTravelAgent();
event.setTo(to);
+ event.useTravelAgent(true);
+
+ // System.out.println("to : "+to);
+
+ int radius = w.getPortalSearchWidth();
+
+ // System.out.println("Searching in a "+radius+" radius!");
+ agent.setSearchRadius(radius);
+ // System.out.println("After travelagent : "+event.getTo());
+
+
}
}
View
9 src/com/guntherdw/bukkit/tweakcraft/Packages/Argument.java
@@ -25,6 +25,7 @@
private Integer id;
private String argname;
private Object argvalue;
+ private boolean _used;
public Argument(Integer position, String argname, Object argvalue) {
this.id = position; this.argname = argname; this.argvalue = argvalue;
@@ -57,4 +58,12 @@ public Object getArgvalue() {
public void setArgvalue(Object argvalue) {
this.argvalue = argvalue;
}
+
+ public boolean is_used() {
+ return _used;
+ }
+
+ public void set_used(boolean state) {
+ this._used = state;
+ }
}
View
71 src/com/guntherdw/bukkit/tweakcraft/Tools/ArgumentParser.java
@@ -56,6 +56,19 @@ public ArgumentParser(String[] args) {
}
public ArgumentParser() { }
+
+ public void setUsed(String argName, boolean state) {
+ Argument arg = null;
+ // First the named argument map, this is the easiest one.
+ arg = _namedargs.get(argName);
+ if(arg!=null) arg.set_used(state);
+
+ // Second the List<Argument> one, this'll require a for loop
+ for(int x=0; x<_args.size(); x++) {
+ arg = _args.get(x);
+ if(arg.getArgname() != null && arg.getArgname().equals(argName)) arg.set_used(state);
+ }
+ }
public int getSize() {
return _args.size();
@@ -66,48 +79,57 @@ public Object getValue(int pos) {
return null;
else if(pos>this.getSize())
return null;
- else
- return _args.get(pos);
+ else {
+ this.setUsed(_args.get(pos).getArgname(), true);
+ return _args.get(pos).getArgvalue();
+ }
}
public Boolean getBoolean(String argname, Boolean defaultval) {
- if(_namedargs.containsKey(argname))
+ if(_namedargs.containsKey(argname)) {
+ this.setUsed(argname, true);
return Boolean.parseBoolean((String) _namedargs.get(argname).getArgvalue());
- else
+ } else
return defaultval;
}
public Integer getInteger(String argname, Integer defaultval) {
- if(_namedargs.containsKey(argname))
+ if(_namedargs.containsKey(argname)) {
+ this.setUsed(argname, true);
return Integer.parseInt((String) _namedargs.get(argname).getArgvalue());
- else
+ } else
return defaultval;
}
public Boolean getBoolean(int pos, Boolean defaultval) {
- if(pos >=0 && this.getSize()>pos)
+ if(pos >=0 && this.getSize()>pos) {
+ this.setUsed(_args.get(pos).getArgname(), true);
return Boolean.parseBoolean((String) _args.get(pos).getArgvalue());
- else
+ } else
return defaultval;
}
public Integer getInteger(int pos, Integer defaultval) {
- if(pos >=0 && this.getSize()>pos)
+ if(pos >=0 && this.getSize()>pos) {
+ this.setUsed(_args.get(pos).getArgname(), true);
return Integer.parseInt((String)_args.get(pos).getArgvalue());
- else
+ } else
return defaultval;
}
public String getString(int pos, String defaultval) {
- if(pos >=0 && this.getSize()>pos)
+ if(pos >=0 && this.getSize()>pos) {
+ this.setUsed(_args.get(pos).getArgname(), true);
return (String)_args.get(pos).getArgvalue();
- else
+ } else
return defaultval;
}
public String getString(String argname, String defaultval) {
- if(_namedargs.containsKey(argname))
+ if(_namedargs.containsKey(argname)) {
+ this.setUsed(argname, true);
return (String) _namedargs.get(argname).getArgvalue();
+ }
else
return defaultval;
}
@@ -121,6 +143,29 @@ public String getString(String argname, String defaultval) {
return vals;
}
+ public List<Argument> getUnusedArgsList() {
+ List<Argument> vals = new ArrayList<Argument>();
+ for(Argument arg : _args) {
+ if(arg.getArgname()==null || !arg.is_used())
+ vals.add(arg);
+ }
+ return vals;
+ }
+
+ public String[] getUnusedArgs() {
+ // return (String[]) this.getUnusedArgsList().toArray();
+ List<Argument> als = this.getUnusedArgsList();
+ String[] args = new String[als.size()];
+ for(int x=0; x<als.size(); x++) {
+ String tmp = "";
+ Argument arg = als.get(x);
+ if(arg.getArgname()!=null) { tmp+=arg.getArgname()+":"; }
+ if(arg.getArgvalue()!=null) tmp+=(String)arg.getArgvalue();
+ args[x] = tmp;
+ }
+ return args;
+ }
+
public String[] getNormalArgs() {
List<Argument> al = this.getDefaultArguments();
String[] lijst = new String[al.size()];
View
470 src/com/guntherdw/bukkit/tweakcraft/Util/TweakTravelAgent.java
@@ -0,0 +1,470 @@
+/*
+ * 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.Util;
+
+import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.TravelAgent;
+import org.bukkit.World;
+import org.bukkit.event.world.PortalCreateEvent;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * @author Whoever wrote it, Bukkit Team, Notch?, GuntherDW
+ */
+public class TweakTravelAgent implements TravelAgent {
+
+ private Random random = new Random();
+
+ private int searchRadius = 64;
+ private int creationRadius = 14; // 16 -> 14
+ private boolean canCreatePortal = true;
+ private TweakcraftUtils plugin = null;
+
+ private Map<Integer, Boolean> buildable;
+
+ public TweakTravelAgent(TweakcraftUtils instance) {this.plugin=instance;}
+
+ public void fillBuildableMap() {
+ if(buildable==null)buildable=new HashMap<Integer, Boolean>();
+ buildable.clear();
+ buildable.put(Material.AIR.getId(), false);
+ buildable.put(Material.STONE.getId(), true);
+ buildable.put(Material.GRASS.getId(), true);
+ buildable.put(Material.DIRT.getId(), true);
+ buildable.put(Material.COBBLESTONE.getId(), true);
+ buildable.put(Material.WOOD.getId(), true);
+ buildable.put(Material.SAPLING.getId(), false);
+ buildable.put(Material.BEDROCK.getId(), true);
+ buildable.put(Material.WATER.getId(), false);
+ buildable.put(Material.STATIONARY_WATER.getId(), false);
+ buildable.put(Material.LAVA.getId(), false);
+ buildable.put(Material.STATIONARY_LAVA.getId(), false);
+ buildable.put(Material.SAND.getId(), true);
+ buildable.put(Material.GRAVEL.getId(), true);
+ buildable.put(Material.GOLD_ORE.getId(), true);
+ buildable.put(Material.IRON_ORE.getId(), true);
+ buildable.put(Material.COAL_ORE.getId(), true);
+ buildable.put(Material.LOG.getId(), true);
+ buildable.put(Material.LEAVES.getId(), true);
+ buildable.put(Material.SPONGE.getId(), true);
+ buildable.put(Material.GLASS.getId(), true);
+ buildable.put(Material.LAPIS_ORE.getId(), true);
+ buildable.put(Material.LAPIS_BLOCK.getId(), true);
+ buildable.put(Material.DISPENSER.getId(), true);
+ buildable.put(Material.SANDSTONE.getId(), true);
+ buildable.put(Material.NOTE_BLOCK.getId(), true);
+ buildable.put(Material.BED_BLOCK.getId(), true);
+ buildable.put(Material.POWERED_RAIL.getId(), false);
+ buildable.put(Material.DETECTOR_RAIL.getId(), false);
+ buildable.put(Material.PISTON_STICKY_BASE.getId(), true);
+ buildable.put(Material.WEB.getId(), false);
+ buildable.put(Material.LONG_GRASS.getId(), false);
+ buildable.put(Material.DEAD_BUSH.getId(), false);
+ buildable.put(Material.PISTON_BASE.getId(), true);
+ buildable.put(Material.PISTON_EXTENSION.getId(), false);
+ buildable.put(Material.WOOL.getId(), true);
+ buildable.put(Material.PISTON_MOVING_PIECE.getId(), true);
+ buildable.put(Material.YELLOW_FLOWER.getId(), false);
+ buildable.put(Material.RED_ROSE.getId(), false);
+ buildable.put(Material.BROWN_MUSHROOM.getId(), false);
+ buildable.put(Material.RED_MUSHROOM.getId(), false);
+ buildable.put(Material.GOLD_BLOCK.getId(), true);
+ buildable.put(Material.IRON_BLOCK.getId(), true);
+ buildable.put(Material.DOUBLE_STEP.getId(), true);
+ buildable.put(Material.STEP.getId(), true);
+ buildable.put(Material.BRICK.getId(), true);
+ buildable.put(Material.TNT.getId(), true);
+ buildable.put(Material.BOOKSHELF.getId(), true);
+ buildable.put(Material.MOSSY_COBBLESTONE.getId(), true);
+ buildable.put(Material.OBSIDIAN.getId(), true);
+ }
+
+ public Location findOrCreate(Location location) {
+ /* WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
+ worldServer.chunkProviderServer.forceChunkLoad = true; */
+ // Attempt to find a Portal.
+ Location resultLocation = this.findPortal(location);
+ // If a Portal cannot be found we will attempt to create one.
+ if (resultLocation == null) {
+ // Attempt to create a portal, return if it was successful or not.
+ if (this.canCreatePortal && this.createPortal(location)) {
+ // Now find that portals location.
+ resultLocation = this.findPortal(location);
+ } else {
+ // Fallback onto the original location.
+ resultLocation = location;
+ }
+ }
+ /* worldServer.chunkProviderServer.forceChunkLoad = false; */
+ // Return our resulting portal location.
+ return resultLocation;
+ }
+
+ public Location findPortal(Location location) {
+ // net.minecraft.server.World world = ((CraftWorld) location.getWorld()).getHandle();
+ World world = location.getWorld();
+ // short short1 = 128;
+ double d0 = -1.0D;
+ int i = 0;
+ int j = 0;
+ int k = 0;
+ int l = location.getBlockX();
+ int i1 = location.getBlockZ();
+
+ double d1;
+
+ for (int j1 = l - this.searchRadius; j1 <= l + this.searchRadius; ++j1) {
+ double d2 = (double) j1 + 0.5D - location.getX();
+
+ for (int k1 = i1 - this.searchRadius; k1 <= i1 + this.searchRadius; ++k1) {
+ double d3 = (double) k1 + 0.5D - location.getZ();
+
+ for (int l1 = 127; l1 >= 0; --l1) {
+ if (world.getBlockAt(j1, l1, k1).getTypeId() == Material.PORTAL.getId()) {
+ while (world.getBlockAt(j1, l1 - 1, k1).getTypeId() == Material.PORTAL.getId()) {
+ --l1;
+ }
+
+ d1 = (double) l1 + 0.5D - location.getY();
+ double d4 = d2 * d2 + d1 * d1 + d3 * d3;
+
+ if (d0 < 0.0D || d4 < d0) {
+ d0 = d4;
+ i = j1;
+ j = l1;
+ k = k1;
+ }
+ }
+ }
+ }
+ }
+
+ if (d0 >= 0.0D) {
+ double d5 = (double) i + 0.5D;
+ double d6 = (double) j + 0.5D;
+
+ d1 = (double) k + 0.5D;
+ if (world.getBlockAt(i - 1, j, k).getTypeId() == Material.PORTAL.getId()) {
+ d5 -= 0.5D;
+ }
+
+ if (world.getBlockAt(i + 1, j, k).getTypeId() == Material.PORTAL.getId()) {
+ d5 += 0.5D;
+ }
+
+ if (world.getBlockAt(i, j, k - 1).getTypeId() == Material.PORTAL.getId()) {
+ d1 -= 0.5D;
+ }
+
+ if (world.getBlockAt(i, j, k + 1).getTypeId() == Material.PORTAL.getId()) {
+ d1 += 0.5D;
+ }
+
+ return new Location(location.getWorld(), d5, d6, d1, location.getYaw(), location.getPitch());
+ } else {
+ return null;
+ }
+ }
+
+ public boolean createPortal(Location location) {
+ // net.minecraft.server.World world = ((CraftWorld) location.getWorld()).getHandle();
+ World world = location.getWorld();
+ // byte b0 = 16;
+ double d0 = -1.0D;
+ int i = location.getBlockX();
+ int j = location.getBlockY();
+ int k = location.getBlockZ();
+ int l = i;
+ int i1 = j;
+ int j1 = k;
+ int k1 = 0;
+ int l1 = this.random.nextInt(4);
+
+ int i2;
+ double d1;
+ int j2;
+ double d2;
+ int k2;
+ int l2;
+ int i3;
+ int j3;
+ int k3;
+ int l3;
+ int i4;
+ int j4;
+ int k4;
+ double d3;
+ double d4;
+
+ for (i2 = i - this.creationRadius; i2 <= i + this.creationRadius; ++i2) {
+ d1 = (double) i2 + 0.5D - location.getX();
+
+ for (j2 = k - this.creationRadius; j2 <= k + this.creationRadius; ++j2) {
+ d2 = (double) j2 + 0.5D - location.getZ();
+
+ label271:
+ for (l2 = 127; l2 >= 0; --l2) {
+ if (world.getBlockAt(i2, l2, j2).isEmpty()) {
+ while (l2 > 0 && world.getBlockAt(i2, l2 - 1, j2).isEmpty()) {
+ --l2;
+ }
+
+ for (k2 = l1; k2 < l1 + 4; ++k2) {
+ j3 = k2 % 2;
+ i3 = 1 - j3;
+ if (k2 % 4 >= 2) {
+ j3 = -j3;
+ i3 = -i3;
+ }
+
+ for (l3 = 0; l3 < 3; ++l3) {
+ for (k3 = 0; k3 < 4; ++k3) {
+ for (j4 = -1; j4 < 5; ++j4) {
+ i4 = i2 + (k3 - 1) * j3 + l3 * i3;
+ k4 = l2 + j4;
+ int l4 = j2 + (k3 - 1) * i3 - l3 * j3;
+
+ if (j4 < 0 && !this.isBuildable(world.getBlockAt(i4, k4, l4).getTypeId()) || j4 >= 0 && !world.getBlockAt(i4, k4, l4).isEmpty()) {
+ continue label271;
+ }
+ }
+ }
+ }
+
+ d3 = (double) l2 + 0.5D - location.getY();
+ d4 = d1 * d1 + d3 * d3 + d2 * d2;
+ if (d0 < 0.0D || d4 < d0) {
+ d0 = d4;
+ l = i2;
+ i1 = l2 + 1;
+ j1 = j2;
+ k1 = k2 % 4;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (d0 < 0.0D) {
+ for (i2 = i - this.creationRadius; i2 <= i + this.creationRadius; ++i2) {
+ d1 = (double) i2 + 0.5D - location.getX();
+
+ for (j2 = k - this.creationRadius; j2 <= k + this.creationRadius; ++j2) {
+ d2 = (double) j2 + 0.5D - location.getZ();
+
+ label219:
+ for (l2 = 127; l2 >= 0; --l2) {
+ if (world.getBlockAt(i2, l2, j2).isEmpty()) {
+ while (l2 > 0 && world.getBlockAt(i2, l2 - 1, j2).isEmpty()) {
+ --l2;
+ }
+
+ for (k2 = l1; k2 < l1 + 2; ++k2) {
+ j3 = k2 % 2;
+ i3 = 1 - j3;
+
+ for (l3 = 0; l3 < 4; ++l3) {
+ for (k3 = -1; k3 < 5; ++k3) {
+ j4 = i2 + (l3 - 1) * j3;
+ i4 = l2 + k3;
+ k4 = j2 + (l3 - 1) * i3;
+ if (k3 < 0 && !this.isBuildable(world.getBlockAt(j4, i4, k4).getTypeId()) || k3 >= 0 && !world.getBlockAt(j4, i4, k4).isEmpty()) {
+ continue label219;
+ }
+ }
+ }
+
+ d3 = (double) l2 + 0.5D - location.getY();
+ d4 = d1 * d1 + d3 * d3 + d2 * d2;
+ if (d0 < 0.0D || d4 < d0) {
+ d0 = d4;
+ l = i2;
+ i1 = l2 + 1;
+ j1 = j2;
+ k1 = k2 % 2;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ int i5 = l;
+ int j5 = i1;
+
+ j2 = j1;
+ int k5 = k1 % 2;
+ int l5 = 1 - k5;
+
+ if (k1 % 4 >= 2) {
+ k5 = -k5;
+ l5 = -l5;
+ }
+
+ boolean flag;
+
+ // CraftBukkit start - portal create event
+ java.util.ArrayList<org.bukkit.block.Block> blocks = new java.util.ArrayList<org.bukkit.block.Block>();
+ // Find out what blocks the portal is going to modify, duplicated from below
+ // CraftWorld craftWorld = ((WorldServer) world).getWorld();
+ // World world = location.getWorld();
+
+ if (d0 < 0.0D) {
+ if (i1 < 70) {
+ i1 = 70;
+ }
+
+ if (i1 > 118) {
+ i1 = 118;
+ }
+
+ j5 = i1;
+
+ for (l2 = -1; l2 <= 1; ++l2) {
+ for (k2 = 1; k2 < 3; ++k2) {
+ for (j3 = -1; j3 < 3; ++j3) {
+ i3 = i5 + (k2 - 1) * k5 + l2 * l5;
+ l3 = j5 + j3;
+ k3 = j2 + (k2 - 1) * l5 - l2 * k5;
+ org.bukkit.block.Block b = world.getBlockAt(i3, l3, k3);
+ if (!blocks.contains(b)) {
+ blocks.add(b);
+ }
+ }
+ }
+ }
+ }
+
+ for (l2 = 0; l2 < 4; ++l2) {
+ for (k2 = 0; k2 < 4; ++k2) {
+ for (j3 = -1; j3 < 4; ++j3) {
+ i3 = i5 + (k2 - 1) * k5;
+ l3 = j5 + j3;
+ k3 = j2 + (k2 - 1) * l5;
+ org.bukkit.block.Block b = world.getBlockAt(i3, l3, k3);
+ if (!blocks.contains(b)) {
+ blocks.add(b);
+ }
+ }
+ }
+ }
+
+ PortalCreateEvent event = new PortalCreateEvent(blocks, world);
+ plugin.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return false;
+ }
+ // CraftBukkit end
+
+ if (d0 < 0.0D) {
+ if (i1 < 70) {
+ i1 = 70;
+ }
+
+ if (i1 > 118) {
+ i1 = 118;
+ }
+
+ j5 = i1;
+
+ for (l2 = -1; l2 <= 1; ++l2) {
+ for (k2 = 1; k2 < 3; ++k2) {
+ for (j3 = -1; j3 < 3; ++j3) {
+ i3 = i5 + (k2 - 1) * k5 + l2 * l5;
+ l3 = j5 + j3;
+ k3 = j2 + (k2 - 1) * l5 - l2 * k5;
+ flag = j3 < 0;
+ world.getBlockAt(i3, l3, k3).setTypeId(flag ? Material.OBSIDIAN.getId() : 0, false);
+ }
+ }
+ }
+ }
+
+ for (l2 = 0; l2 < 4; ++l2) {
+ // world.suppressPhysics = true;
+
+ for (k2 = 0; k2 < 4; ++k2) {
+ for (j3 = -1; j3 < 4; ++j3) {
+ i3 = i5 + (k2 - 1) * k5;
+ l3 = j5 + j3;
+ k3 = j2 + (k2 - 1) * l5;
+ flag = k2 == 0 || k2 == 3 || j3 == -1 || j3 == 3;
+ world.getBlockAt(i3, l3, k3).setTypeId(flag ? Material.OBSIDIAN.getId() : Material.PORTAL.getId(), false);
+ }
+ }
+
+ // world.suppressPhysics = false;
+
+ for (k2 = 0; k2 < 4; ++k2) {
+ for (j3 = -1; j3 < 4; ++j3) {
+ i3 = i5 + (k2 - 1) * k5;
+ l3 = j5 + j3;
+ k3 = j2 + (k2 - 1) * l5;
+ world.getBlockAt(i3, l3, k3).setTypeId(world.getBlockTypeIdAt(i3, l3, k3));
+ }
+ }
+ //world.
+ }
+
+ return true;
+ }
+
+
+
+
+ public TravelAgent setSearchRadius(int radius) {
+ this.searchRadius = radius;
+ return this;
+ }
+
+ public int getSearchRadius() {
+ return this.searchRadius;
+ }
+
+ public TravelAgent setCreationRadius(int radius) {
+ this.creationRadius = radius < 2 ? 0 : radius - 2;
+ return this;
+ }
+
+ public int getCreationRadius() {
+ return this.creationRadius;
+ }
+
+ public boolean getCanCreatePortal() {
+ return this.canCreatePortal;
+ }
+
+ public void setCanCreatePortal(boolean create) {
+ this.canCreatePortal = create;
+ }
+
+ public boolean isBuildable(int type) {
+ Boolean b = buildable.get(type);
+ if(b!=null) return b;
+ return false;
+ }
+
+}
View
4 src/com/guntherdw/bukkit/tweakcraft/Worlds/IWorld.java
@@ -31,6 +31,10 @@
public abstract org.bukkit.World getNetherWorld();
+ public abstract int getPortalSearchWidth();
+
+ public abstract void setPortalSearchWidth(int searchWidth);
+
public abstract String getName();
public abstract void loadWorld();
View
13 src/com/guntherdw/bukkit/tweakcraft/Worlds/TweakWorld.java
@@ -38,6 +38,7 @@
private boolean tooldurability = true;
private boolean netherenabled = false;
private boolean keepspawnactive = false;
+ private int portalSearchWidth = 128;
private String worldName = "";
private org.bukkit.World.Environment environment;
private WorldManager wm;
@@ -150,6 +151,7 @@ public void loadWorld(WorldManager wm, String foldername, org.bukkit.World.Envir
// wm.getPlugin().getLogger().info("[TweakcraftUtils] Creating new world!");
environment = env;
world = wm.getPlugin().getServer().createWorld(worldName, environment);
+ world.setKeepSpawnInMemory(this.getSpawnChunksActive());
} else {
// wm.getPlugin().getLogger().info("[TweakcraftUtils] This world already existed!");
environment = world.getEnvironment();
@@ -176,7 +178,8 @@ public IWorld getWorld() {
}
public void setSpawnChunksActive(boolean state) {
- this.world.setKeepSpawnInMemory(state);
+ // this.world.setKeepSpawnInMemory(state);
+ if(world!=null) this.world.setKeepSpawnInMemory(state);
this.keepspawnactive = state;
}
@@ -187,6 +190,14 @@ public boolean getSpawnChunksActive() {
public org.bukkit.World getBukkitWorld() {
return world;
}
+
+ public int getPortalSearchWidth() {
+ return this.portalSearchWidth;
+ }
+
+ public void setPortalSearchWidth(int searchWidth) {
+ this.portalSearchWidth = searchWidth;
+ }
@Override
public World getNetherWorld() {
View
2 src/com/guntherdw/bukkit/tweakcraft/Worlds/WorldManager.java
@@ -90,6 +90,7 @@ public void setupWorlds() {
boolean addnether = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".addnether", false);
boolean spawnchunksactive = plugin.getConfiguration().getBoolean("worlds.extraworlds." + node + ".spawnchunksactive", false);
int viewdistance = plugin.getConfiguration().getInt("worlds.extraworlds." + node + ".viewdistance", defaultviewdistance);
+ int portalSearchRadius = plugin.getConfiguration().getInt("worlds.extraworlds." + node + ".portalSearchRadius", 128);
@@ -117,6 +118,7 @@ public void setupWorlds() {
TweakWorld tw = new TweakWorld(this, node, wenv, pvp, monsters, animals, viewdistance, durability, enabled);
if(addnether) tw.addNether();
tw.setSpawnChunksActive(spawnchunksactive);
+ tw.setPortalSearchWidth(portalSearchRadius);
worlds.put(node, tw);
} else {

0 comments on commit 92738e1

Please sign in to comment.