Skip to content

Commit

Permalink
[3.0b3] More work on worldGuard import and ProtectionStone support, n…
Browse files Browse the repository at this point in the history
…ot finished yet though.

- Added Enderpearl flag(disables tping using enderpearls).
- Added playerpvpdamage flag(disables pvp damage).
- Added SoilDry flag(disables drying out of soil).
- Added Mycelium flag(disables spread of mycelium).
- Added lightning flag(disables lightning strikes in an area).
  • Loading branch information
Meaglin committed Aug 17, 2014
1 parent 31326c3 commit e59085a
Show file tree
Hide file tree
Showing 19 changed files with 645 additions and 157 deletions.
4 changes: 2 additions & 2 deletions Builder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<path id="classpath">
<fileset dir="libs">
<include name="craftbukkit.jar" />
<include name="WorldEdit.jar" />
<include name="worldedit-5.6.3.jar" />
<include name="Vault-1.4.1.jar" />
<include name="WorldGuard.jar" />
<include name="VirtualPlayers.jar" />
Expand Down Expand Up @@ -63,7 +63,7 @@
<exclude name="META-INF/*" />
</zipfileset>
</jar>
<zip destfile="../Zones-3.0b2.zip" >
<zip destfile="../Zones-3.0b3.zip" >
<fileset dir=".." includes="Zones.jar" />
<zipfileset dir="${src}/com/zones/config/" >
<include name="*.properties" />
Expand Down
Binary file removed libs/WorldEdit.jar
Binary file not shown.
Binary file added libs/worldedit-5.6.3.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Zones
main: com.zones.Zones
version: 3.0b2
version: 3.0b3
author: 'Meaglin'
authors: [ 'Mysteryman', 'GunterDW' ]
depend: [ 'Vault' ]
Expand Down
39 changes: 3 additions & 36 deletions src/com/zones/ZoneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@

import org.bukkit.entity.Player;

import com.zones.model.forms.ZoneCuboid;
import com.zones.model.forms.ZoneCylinder;
import com.zones.model.forms.ZoneNPoly;
import com.zones.model.forms.ZoneSphere;
import com.zones.model.types.ZoneNormal;
import com.zones.persistence.Vertice;
import com.zones.persistence.Zone;
import com.zones.selection.ZoneSelection;
import com.zones.world.WorldManager;
Expand Down Expand Up @@ -53,7 +48,7 @@ public void cleanUp(WorldManager world) {
public void load(WorldManager world) {
cleanUp(world);
try {
List<Zone> zones = plugin.getMysqlDatabase().get(world.getWorldName());
List<Zone> zones = plugin.getMysqlDatabase().getWorld(world.getWorldName());
addZones(world, loadFromPersistentData(world, zones));
} catch(Exception e) {
log.warning("[Zones] Error loading world " + world.getWorldName() + ".");
Expand Down Expand Up @@ -89,36 +84,8 @@ public ZoneNormal loadFromPersistentData(WorldManager world, Zone zone) {
return null;
}
temp.initialize(plugin, world, zone);
List<Vertice> vertices = zone.getVertices();

if(zone.getFormtype().equalsIgnoreCase("ZoneCuboid")) {
if (vertices.size() == 2) {
temp.setForm(new ZoneCuboid(vertices, zone.getMiny(), zone.getMaxy()));
} else {
log.info("[Zones] Missing zone vertex for cuboid zone id: " + zone.getId());
return null;
}
} else if(zone.getFormtype().equalsIgnoreCase("ZoneNPoly")) {
if (vertices.size() > 2) {
temp.setForm(new ZoneNPoly(vertices, zone.getMiny() , zone.getMaxy()));
} else {
log.warning("[Zones] Bad data for zone: " + zone.getId());
return null;
}
} else if(zone.getFormtype().equalsIgnoreCase("ZoneCylinder")) {
if (vertices.size() == 2) {
temp.setForm(new ZoneCylinder(vertices, zone.getMiny(), zone.getMaxy()));
} else {
log.info("[Zones] Missing zone vertex for Cylinder zone id: " + zone.getId());
return null;
}
} else if(zone.getFormtype().equalsIgnoreCase("ZoneSphere")) {
if (vertices.size() == 1) {
temp.setForm(new ZoneSphere(vertices, zone.getMiny(), zone.getMaxy()));
} else {
log.info("[Zones] Missing zone vertex for Sphere zone id: " + zone.getId());
return null;
}
if(!temp.loadForm()) {
return null;
}
} catch(Exception e) {
log.warning("[Zones] Error loading zone " + zone.getId() + ".");
Expand Down
1 change: 1 addition & 0 deletions src/com/zones/ZonesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class ZonesConfig {
public static final String PROTECTED_CANNOT_DEGRADE = ChatColor.RED + "You cannot remove this upgrade from the zone.";

public static final String PROTECTED_ZONE_UPGRADED = ChatColor.GREEN + "Zone {zname} upgraded.";
public static final String PROTECTED_ZONE_DEGRADED = ChatColor.GREEN + "Zone {zname} degraded.";
public static final String PROTECTED_CANNOT_UPGRADE = ChatColor.RED + "You cannot upgrade this zone.";

public static final String PLAYER_CANT_USE_COMMAND_IN_ZONE = ChatColor.RED + "You cannot use this command in zone '{zname}' !";
Expand Down
202 changes: 202 additions & 0 deletions src/com/zones/command/imports/WorldGuardImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@

import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.EntityType;

import com.meaglin.json.JSONArray;
import com.meaglin.json.JSONObject;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Location;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.zones.Zones;
import com.zones.model.settings.ZoneVar;
import com.zones.persistence.Vertice;
import com.zones.persistence.Zone;

public class WorldGuardImport {
public static List<Zone> importAll(Zones plugin) {
List<Zone> zones = new ArrayList<>();
WorldGuardPlugin wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
if(wg == null) {
return zones;
}
for(World w : plugin.getServer().getWorlds()) {
RegionManager m = wg.getRegionManager(w);
for(Entry<String, ProtectedRegion> e : m.getRegions().entrySet()) {
Expand Down Expand Up @@ -92,8 +102,200 @@ public static List<Zone> importAll(Zones plugin) {
user.put("access", defaultAccess);
grouplist.put(group, user);
}
parseFlags(z, r);
zones.add(z);
}
}
return zones;
}

private static void parseFlags(Zone z, ProtectedRegion r) {
JSONObject settings = z.getConfig().getJSONObject("settings");
for (Entry<Flag<?>, Object> e : r.getFlags().entrySet()) {
switch (e.getKey().getName()) {
case "passthrough": // TODO: check
break;
// arbitrary
case "build":
break;
// deprecated
case "construct":
break;
case "pvp":
settings.put(ZoneVar.PLAYER_PVP_DAMAGE.getName(), r.getFlag(DefaultFlag.PVP) == State.ALLOW);
break;
case "mob-damage": // specific flag.
settings.put(ZoneVar.PLAYER_ENTITY_DAMAGE.getName(), r.getFlag(DefaultFlag.MOB_DAMAGE) == State.ALLOW);
break;
case "mob-spawning":
settings.put(ZoneVar.MOBS.getName(), r.getFlag(DefaultFlag.MOB_SPAWNING) == State.ALLOW);
break;
case "creeper-explosion":
settings.put(ZoneVar.CREEPER_EXPLOSION.getName(), r.getFlag(DefaultFlag.CREEPER_EXPLOSION) == State.ALLOW);
break;
case "enderdragon-block-damage":
break; // TODO: implement
case "ghast-fireball":
break; // TODO: implement
case "other-explosion":
break; // TODO: implement
case "sleep":
break; // TODO: implement
case "tnt":
settings.put(ZoneVar.DYNAMITE.getName(), r.getFlag(DefaultFlag.TNT) == State.ALLOW);
break;
case "lighter":
settings.put(ZoneVar.LIGHTER.getName(), r.getFlag(DefaultFlag.TNT) == State.ALLOW);
break;
case "fire-spread":
settings.put(ZoneVar.FIRE.getName(), r.getFlag(DefaultFlag.FIRE_SPREAD) == State.ALLOW);
break;
case "lava-fire":
settings.put(ZoneVar.FIRE.getName(), r.getFlag(DefaultFlag.LAVA_FIRE) == State.ALLOW);
break;
case "lightning":
settings.put(ZoneVar.LIGHTNING.getName(), r.getFlag(DefaultFlag.LIGHTNING) == State.ALLOW);
break;
case "chest-access": // specific flag.
break;
case "water-flow":
settings.put(ZoneVar.WATER.getName(), r.getFlag(DefaultFlag.WATER_FLOW) == State.ALLOW);
break;
case "lava-flow":
settings.put(ZoneVar.LAVA.getName(), r.getFlag(DefaultFlag.LAVA_FLOW) == State.ALLOW);
break;
case "use": // specific flag.
break;
case "vehicle-place": // specific flag.
break;
case "vehicle-destroy": // specific flag.
break;
case "pistons": // WHY THE FUDGE?
break; // TODO: implement
case "snow-fall":
settings.put(ZoneVar.SNOW_FALL.getName(), r.getFlag(DefaultFlag.SNOW_FALL) == State.ALLOW);
break;
case "snow-melt":
settings.put(ZoneVar.SNOW_MELT.getName(), r.getFlag(DefaultFlag.SNOW_MELT) == State.ALLOW);
break;
case "ice-form":
settings.put(ZoneVar.ICE_FORM.getName(), r.getFlag(DefaultFlag.ICE_FORM) == State.ALLOW);
break;
case "ice-melt":
settings.put(ZoneVar.ICE_MELT.getName(), r.getFlag(DefaultFlag.ICE_MELT) == State.ALLOW);
break;
case "mushroom-growth":
settings.put(ZoneVar.MUSHROOM_SPREAD.getName(), r.getFlag(DefaultFlag.MUSHROOMS) == State.ALLOW);
break;
case "leaf-decay":
settings.put(ZoneVar.LEAF_DECAY.getName(), r.getFlag(DefaultFlag.LEAF_DECAY) == State.ALLOW);
break;
case "grass-growth":
settings.put(ZoneVar.GRASS_GROWTH.getName(), r.getFlag(DefaultFlag.GRASS_SPREAD) == State.ALLOW);
break;
case "mycelium-spread":
settings.put(ZoneVar.MYCELIUM_SPREAD.getName(), r.getFlag(DefaultFlag.GRASS_SPREAD) == State.ALLOW);
break;
case "vine-growth":
settings.put(ZoneVar.VINES_GROWTH.getName(), r.getFlag(DefaultFlag.VINE_GROWTH) == State.ALLOW);
break;
case "soil-dry":
settings.put(ZoneVar.SOIL_DRY.getName(), r.getFlag(DefaultFlag.SOIL_DRY) == State.ALLOW);
break;
case "enderman-grief":
settings.put(ZoneVar.ENDER_GRIEFING.getName(), r.getFlag(DefaultFlag.ENDER_BUILD) == State.ALLOW);
break;
case "invincible":
break; // TODO: implement
case "exp-drops":
break; // TODO: implement
case "send-chat":
break;
case "receive-chat":
break;
case "entry": // specific flag.
break;
case "exit": // specific flag.
break;
case "item-drop": // specific flag.
break;
case "enderpearl":
settings.put(ZoneVar.ENDERPEARL.getName(), r.getFlag(DefaultFlag.ENDERPEARL) == State.ALLOW);
break;
case "entity-painting-destroy": // specific flag.
break;
case "entity-item-frame-destroy": // specific flag.
break;
case "potion-splash":
break; // TODO: implement
case "greeting":
settings.put(ZoneVar.ENTER_MESSAGE.getName(), r.getFlag(DefaultFlag.GREET_MESSAGE));
break;
case "farewell":
settings.put(ZoneVar.LEAVE_MESSAGE.getName(), r.getFlag(DefaultFlag.FAREWELL_MESSAGE));
break;
case "notify-enter":
settings.put(ZoneVar.NOTIFY.getName(), r.getFlag(DefaultFlag.NOTIFY_ENTER));
break;
case "notify-leave":
settings.put(ZoneVar.NOTIFY.getName(), r.getFlag(DefaultFlag.NOTIFY_LEAVE));
break;
case "deny-spawn":
JSONArray arr = new JSONArray();
for(EntityType type : EntityType.values()) {
if(!r.getFlag(DefaultFlag.DENY_SPAWN).contains(type)) {
arr.add(type.name());
}
}
settings.put(ZoneVar.ALLOWED_ANIMALS.getName(), arr);
settings.put(ZoneVar.ALLOWED_MOBS.getName(), arr);
break;
case "game-mode":
break; // TODO: implement
case "heal-delay": // We are not a very statefull plugin.
break; // TODO: implement
case "heal-amount": // We are not a very statefull plugin.
break; // TODO: implement
case "heal-min-health": // We are not a very statefull plugin.
break; // TODO: implement
case "heal-max-health": // We are not a very statefull plugin.
break; // TODO: implement
case "feed-delay": // We are not a very statefull plugin.
break; // TODO: implement
case "feed-amount": // We are not a very statefull plugin.
break; // TODO: implement
case "feed-min-hunger": // We are not a very statefull plugin.
break; // TODO: implement
case "feed-max-hunger": // We are not a very statefull plugin.
break; // TODO: implement
case "teleport":
break; // TODO: implement
case "spawn":
JSONObject obj = new JSONObject();
Location loc = r.getFlag(DefaultFlag.SPAWN_LOC);
obj.put("world", loc.getWorld().getName())
.put("x", loc.getPosition().getX())
.put("y", loc.getPosition().getY())
.put("z", loc.getPosition().getZ())
.put("yaw", loc.getYaw())
.put("pitch", loc.getPitch());
settings.put(ZoneVar.SPAWN_LOCATION.getName(), obj);
break;
case "allow-shop":
break; // TODO: implement
case "buyable":
settings.put(ZoneVar.BUY_ALLOWED.getName(), r.getFlag(DefaultFlag.BUYABLE));
break;
case "price":
settings.put(ZoneVar.BUY_PRICE.getName(), r.getFlag(DefaultFlag.PRICE));
break;
case "blocked-cmds":
settings.put(ZoneVar.DENIED_COMMANDS.getName(), new JSONArray(r.getFlag(DefaultFlag.BLOCKED_CMDS)));
break;
case "allowed-cmds":
settings.put(ZoneVar.ALLOWED_COMMANDS.getName(), new JSONArray(r.getFlag(DefaultFlag.ALLOWED_CMDS)));
break;
}
}
}
}
13 changes: 12 additions & 1 deletion src/com/zones/listeners/ZonesBlockListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void onBlockFade(BlockFadeEvent event) {
Material mat = block.getType();

switch(mat) {
case SNOW: case ICE: break;
case SNOW: case ICE: case SOIL:break;
default: return;
}

Expand All @@ -201,6 +201,11 @@ public void onBlockFade(BlockFadeEvent event) {
event.setCancelled(true);
}
break;
case SOIL:
if(!wm.testFlag(event.getBlock(), ZoneVar.SOIL_DRY)) {
event.setCancelled(true);
}
break;
}
}

Expand All @@ -211,6 +216,7 @@ public void onBlockSpread(org.bukkit.event.block.BlockSpreadEvent event) {
case BROWN_MUSHROOM:
case RED_MUSHROOM:
case VINE:
case MYCEL:
break;
default: return;
}
Expand All @@ -234,6 +240,11 @@ public void onBlockSpread(org.bukkit.event.block.BlockSpreadEvent event) {
event.setCancelled(true);
}
break;
case MYCEL:
if(!wm.testFlag(event.getBlock(), ZoneVar.MYCELIUM_SPREAD)) {
event.setCancelled(true);
}
break;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/com/zones/listeners/ZonesEntityListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public void onEntityDamage(EntityDamageEvent event) {
sub = ZoneVar.PLAYER_CONTACT_DAMAGE;
break;
case ENTITY_ATTACK:
if(attacker instanceof Player) {
sub = ZoneVar.PLAYER_PVP_DAMAGE;
break;
}
sub = ZoneVar.PLAYER_ENTITY_DAMAGE;
break;
case SUFFOCATION:
Expand Down Expand Up @@ -130,6 +134,8 @@ public void onEntityDamage(EntityDamageEvent event) {
sub = ZoneVar.PLAYER_VOID_DAMAGE;
break;
}

// TODO: check for unknown types.
if((sub == null && !wm.testFlag(defender.getLocation(), ZoneVar.HEALTH)) ||
!wm.canReceiveDamage((Player) defender, sub)) {
event.setCancelled(true);
Expand Down
Loading

0 comments on commit e59085a

Please sign in to comment.