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.PlayerTeleportEvent;
import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
public class MVPlayerListener extends PlayerListener {
@ -89,7 +90,7 @@ public class MVPlayerListener extends PlayerListener {
event.getPlayer().sendMessage("If you just wanna see all of the Multiverse Help, type: " + ChatColor.GREEN + "/mv");
}
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
this.plugin.removePlayerSession(event.getPlayer());
@ -113,5 +114,18 @@ public class MVPlayerListener extends PlayerListener {
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;
import java.util.logging.Level;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
@ -40,7 +42,6 @@ public class MVTeleport {
// TODO: Make this configurable
Location safe = checkAboveAndBelowLocation(l, 6, 9);
if (safe != null) {
System.out.print("Safe was NULL!");
safe.setX(safe.getBlockX() + .5);
safe.setZ(safe.getBlockZ() + .5);
}
@ -64,9 +65,7 @@ public class MVTeleport {
}
// We've already checked zero right above this.
int currentLevel = 1;
System.out.print("Checking Level: 0");
while (currentLevel <= tolerance) {
System.out.print("Checking Level: " + currentLevel);
// Check above
locToCheck = l.clone();
locToCheck.add(0, currentLevel, 0);
@ -176,7 +175,7 @@ public class MVTeleport {
l.setX(l.getBlockX() + .5);
l.setZ(l.getBlockZ() + .5);
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;
}
Location safeLocation = this.getSafeLocation(l);
@ -186,10 +185,10 @@ public class MVTeleport {
safeLocation.setY(safeLocation.getBlockY() + .5);
}
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;
}
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;
}

View File

@ -8,6 +8,7 @@ import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.util.config.Configuration;
@ -90,6 +91,7 @@ public class MVWorld {
*/
private String generator;
private Permission permission;
private Permission exempt;
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
this.config = config;
@ -133,8 +135,10 @@ public class MVWorld {
config.save();
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 {
this.plugin.getServer().getPluginManager().addPermission(this.permission);
this.plugin.getServer().getPluginManager().addPermission(this.exempt);
addToUpperLists(this.permission);
} catch (IllegalArgumentException e) {
}
@ -156,19 +160,28 @@ public class MVWorld {
config.save();
}
private void addToUpperLists(Permission permission2) {
private void addToUpperLists(Permission permission) {
Permission all = this.plugin.getServer().getPluginManager().getPermission("multiverse.*");
Permission allWorlds = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
if (all == null) {
all = new Permission("multiverse.*");
this.plugin.getServer().getPluginManager().addPermission(all);
}
Permission allExemption = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*");
if (allWorlds == null) {
allWorlds = new Permission("multiverse.access.*");
this.plugin.getServer().getPluginManager().addPermission(allWorlds);
}
all.getChildren().put(this.permission.getName(), true);
allWorlds.getChildren().put(this.permission.getName(), true);
allWorlds.getChildren().put(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(allWorlds);
}
@ -565,12 +578,16 @@ public class MVWorld {
public Permission getPermission() {
return this.permission;
}
public int getCurrency() {
return this.currency;
}
public double getPrice() {
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)) {
System.out.print("Found the dest key!");
Class<? extends Destination> myClass = this.destList.get(idenChar);
try {
Destination mydest = myClass.newInstance();
System.out.print(idenChar);
if(!mydest.isThisType((MultiverseCore) this.plugin, dest)) {
System.out.print("Invalid A!");
return new InvalidDestination();
}
mydest.setDestination(this.plugin, dest);
System.out.print("Valid!");
return mydest;
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
}
}
System.out.print("Invalid C!");
return new InvalidDestination();
}