Add charge for entering worlds, add exemptions

This commit is contained in:
Eric Stokes 2011-07-27 18:12:58 -06:00
parent c81dcb227c
commit 9e1484408c
5 changed files with 47 additions and 21 deletions

@ -1 +1 @@
Subproject commit 48f6246236f4186db020696bfdcc43ce3abea915 Subproject commit 23ea3541607b70673400f506de82ea6a9cfffe3a

View File

@ -10,6 +10,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent; import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
public class MVPlayerListener extends PlayerListener { public class MVPlayerListener extends PlayerListener {
@ -113,5 +114,18 @@ public class MVPlayerListener extends PlayerListener {
return; return;
} }
} }
// Only check payments if it's a different world:
if (!event.getTo().getWorld().equals(event.getFrom().getWorld())) {
// If the player does not have to pay, return now.
if(toWorld.isExempt(event.getPlayer())) {
return;
}
GenericBank bank = plugin.getBank();
if (!bank.hasEnough(event.getPlayer(), toWorld.getPrice(), toWorld.getCurrency(), "You need " + bank.getFormattedAmount(toWorld.getPrice(), toWorld.getCurrency()) + " to enter " + toWorld.getColoredWorldString())) {
event.setCancelled(true);
} else {
bank.pay(event.getPlayer(), toWorld.getPrice(), toWorld.getCurrency());
}
}
} }
} }

View File

@ -1,5 +1,7 @@
package com.onarandombox.MultiverseCore; package com.onarandombox.MultiverseCore;
import java.util.logging.Level;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -40,7 +42,6 @@ public class MVTeleport {
// TODO: Make this configurable // TODO: Make this configurable
Location safe = checkAboveAndBelowLocation(l, 6, 9); Location safe = checkAboveAndBelowLocation(l, 6, 9);
if (safe != null) { if (safe != null) {
System.out.print("Safe was NULL!");
safe.setX(safe.getBlockX() + .5); safe.setX(safe.getBlockX() + .5);
safe.setZ(safe.getBlockZ() + .5); safe.setZ(safe.getBlockZ() + .5);
} }
@ -64,9 +65,7 @@ public class MVTeleport {
} }
// We've already checked zero right above this. // We've already checked zero right above this.
int currentLevel = 1; int currentLevel = 1;
System.out.print("Checking Level: 0");
while (currentLevel <= tolerance) { while (currentLevel <= tolerance) {
System.out.print("Checking Level: " + currentLevel);
// Check above // Check above
locToCheck = l.clone(); locToCheck = l.clone();
locToCheck.add(0, currentLevel, 0); locToCheck.add(0, currentLevel, 0);
@ -176,7 +175,7 @@ public class MVTeleport {
l.setX(l.getBlockX() + .5); l.setX(l.getBlockX() + .5);
l.setZ(l.getBlockZ() + .5); l.setZ(l.getBlockZ() + .5);
e.teleport(l); e.teleport(l);
System.out.print("The first location you gave me was safe!"); //System.out.print("The first location you gave me was safe!");
return true; return true;
} }
Location safeLocation = this.getSafeLocation(l); Location safeLocation = this.getSafeLocation(l);
@ -186,10 +185,10 @@ public class MVTeleport {
safeLocation.setY(safeLocation.getBlockY() + .5); safeLocation.setY(safeLocation.getBlockY() + .5);
} }
e.teleport(safeLocation); e.teleport(safeLocation);
System.out.print("Had to look for a bit, but I found a safe place for ya!" + safeLocation); //System.out.print("Had to look for a bit, but I found a safe place for ya!" + safeLocation);
return true; return true;
} }
System.out.print("Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now."); this.plugin.log(Level.WARNING, "Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now.");
return false; return false;
} }

View File

@ -8,6 +8,7 @@ import java.util.logging.Level;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
import org.bukkit.util.config.Configuration; import org.bukkit.util.config.Configuration;
@ -90,6 +91,7 @@ public class MVWorld {
*/ */
private String generator; private String generator;
private Permission permission; private Permission permission;
private Permission exempt;
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) { public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
this.config = config; this.config = config;
@ -133,8 +135,10 @@ public class MVWorld {
config.save(); config.save();
this.permission = new Permission("multiverse.access." + this.getName(), "Allows access to " + this.getName(), PermissionDefault.TRUE); this.permission = new Permission("multiverse.access." + this.getName(), "Allows access to " + this.getName(), PermissionDefault.TRUE);
this.exempt = new Permission("multiverse.exempt." + this.getName(), "A player who has this does not pay to enter this world, or use any MV portals in it " + this.getName(), PermissionDefault.OP);
try { try {
this.plugin.getServer().getPluginManager().addPermission(this.permission); this.plugin.getServer().getPluginManager().addPermission(this.permission);
this.plugin.getServer().getPluginManager().addPermission(this.exempt);
addToUpperLists(this.permission); addToUpperLists(this.permission);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
@ -156,19 +160,28 @@ public class MVWorld {
config.save(); config.save();
} }
private void addToUpperLists(Permission permission2) { private void addToUpperLists(Permission permission) {
Permission all = this.plugin.getServer().getPluginManager().getPermission("multiverse.*"); Permission all = this.plugin.getServer().getPluginManager().getPermission("multiverse.*");
Permission allWorlds = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*"); Permission allWorlds = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
if (all == null) { Permission allExemption = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*");
all = new Permission("multiverse.*");
this.plugin.getServer().getPluginManager().addPermission(all);
}
if (allWorlds == null) { if (allWorlds == null) {
allWorlds = new Permission("multiverse.access.*"); allWorlds = new Permission("multiverse.access.*");
this.plugin.getServer().getPluginManager().addPermission(allWorlds); this.plugin.getServer().getPluginManager().addPermission(allWorlds);
} }
all.getChildren().put(this.permission.getName(), true); allWorlds.getChildren().put(permission.getName(), true);
allWorlds.getChildren().put(this.permission.getName(), true); if (allExemption == null) {
allExemption = new Permission("multiverse.exempt.*");
this.plugin.getServer().getPluginManager().addPermission(allExemption);
}
allExemption.getChildren().put(this.exempt.getName(), true);
if (all == null) {
all = new Permission("multiverse.*");
this.plugin.getServer().getPluginManager().addPermission(all);
}
all.getChildren().put("multiverse.access.*", true);
all.getChildren().put("multiverse.exempt.*", true);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(all); this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(all);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allWorlds); this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allWorlds);
} }
@ -573,4 +586,8 @@ public class MVWorld {
public double getPrice() { public double getPrice() {
return this.price; return this.price;
} }
public boolean isExempt(Player p) {
return (this.plugin.getPermissions().hasPermission(p, this.exempt.getName(), true));
}
} }

View File

@ -21,23 +21,19 @@ public class DestinationFactory {
} }
if (this.destList.containsKey(idenChar)) { if (this.destList.containsKey(idenChar)) {
System.out.print("Found the dest key!");
Class<? extends Destination> myClass = this.destList.get(idenChar); Class<? extends Destination> myClass = this.destList.get(idenChar);
try { try {
Destination mydest = myClass.newInstance(); Destination mydest = myClass.newInstance();
System.out.print(idenChar); System.out.print(idenChar);
if(!mydest.isThisType((MultiverseCore) this.plugin, dest)) { if(!mydest.isThisType((MultiverseCore) this.plugin, dest)) {
System.out.print("Invalid A!");
return new InvalidDestination(); return new InvalidDestination();
} }
mydest.setDestination(this.plugin, dest); mydest.setDestination(this.plugin, dest);
System.out.print("Valid!");
return mydest; return mydest;
} catch (InstantiationException e) { } catch (InstantiationException e) {
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
} }
} }
System.out.print("Invalid C!");
return new InvalidDestination(); return new InvalidDestination();
} }