Added iConomy support. Currently only works with iConomy 4.4 until Niji fixes 4.5

This commit is contained in:
Drakia 2011-03-20 01:29:55 -07:00
parent 9473ca8f6f
commit 1add1045ca
3 changed files with 138 additions and 43 deletions

10
README
View File

@ -4,7 +4,7 @@
This is a port of the Stargate plugin from hMod. This is a port of the Stargate plugin from hMod.
Create gates that allow for instant-teleportation between large distances. Gates can be always-open, or triggered, they can be hidden, or accessible to everybody, they can share a network, or they can be split into clusters. Create gates that allow for instant-teleportation between large distances. Gates can be always-open, or triggered, they can be hidden, or accessible to everybody, they can share a network, or they can be split into clusters.
This port will import your existing locations.dat file from the hMod Stargate plugin, as well as any custom .gate files you had! This port will import your existing locations.dat file from the hMod Stargate plugin, as well as any custom .gate files you had!
All of the iConomy code was removed. iConomy support added back in, only costs are create, destroy and use. No permission bypasses.
This version of Stargate is still heavily under development. There are going to be issues for a while yet. This version of Stargate is still heavily under development. There are going to be issues for a while yet.
@ -14,7 +14,6 @@ Known Issues
- Vehicle implementation is nowhere near done. - Vehicle implementation is nowhere near done.
- Signs aren't always updating, I don't know what's causing this, I think it's a Bukkit thing. - Signs aren't always updating, I don't know what's causing this, I think it's a Bukkit thing.
- There are many bugs with portal material not showing properly. This is a bug I can not track down, and have no fix for at the moment. - There are many bugs with portal material not showing properly. This is a bug I can not track down, and have no fix for at the moment.
- Multi-world support is VERY BETA. Please don't just say "it doesn't work" I will ignore you.
============= =============
Permissions Permissions
@ -82,10 +81,17 @@ teleport-message - The message when you are teleported
portal-folder - The folder your portal databases are saved in portal-folder - The folder your portal databases are saved in
gate-folder - The folder containing your .gate files gate-folder - The folder containing your .gate files
destroyexplosion - Whether to destroy a stargate with explosions, or stop an explosion if it contains a gates controls. destroyexplosion - Whether to destroy a stargate with explosions, or stop an explosion if it contains a gates controls.
useiconomy - Whether or not to use iConomy
createcost - The cost to create a stargate
destroycost - The cost to destroy a stargate (Can be negative for a "refund"
usecost - The cost to use a stargate
not-enough-money-message - The message displayed if a player lacks money to do something
============= =============
Changes Changes
============= =============
[Version 0.29]
- Added iConomy support. Currently only works with iConomy 4.4 until Niji fixes 4.5
[Version 0.28] [Version 0.28]
- Fixed an issue with removing stargates during load - Fixed an issue with removing stargates during load
[Version 0.27] [Version 0.27]

View File

@ -27,6 +27,8 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.server.PluginEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.event.vehicle.VehicleListener; import org.bukkit.event.vehicle.VehicleListener;
import org.bukkit.event.vehicle.VehicleMoveEvent; import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.event.world.WorldEvent; import org.bukkit.event.world.WorldEvent;
@ -39,22 +41,26 @@ import org.bukkit.util.config.Configuration;
// Permissions // Permissions
import com.nijikokun.bukkit.Permissions.Permissions; import com.nijikokun.bukkit.Permissions.Permissions;
// iConomy
import com.nijiko.coelho.iConomy.iConomy;
/** /**
* Stargate.java - Plug-in for hey0's minecraft mod. * Stargate.java - A customizeable portal plugin for Bukkit
* @author Shaun (sturmeh) * @author Shaun (sturmeh)
* @author Dinnerbone * @author Dinnerbone
* @author Steven "Drakia" Scott
*/ */
public class Stargate extends JavaPlugin { public class Stargate extends JavaPlugin {
// Permissions // Permissions
private static Permissions permissions = null; private static Permissions permissions = null;
private double permVersion = 0;
private final bListener blockListener = new bListener(); private final bListener blockListener = new bListener();
private final pListener playerListener = new pListener(); private final pListener playerListener = new pListener();
private final vListener vehicleListener = new vListener(); private final vListener vehicleListener = new vListener();
private final wListener worldListener = new wListener(); private final wListener worldListener = new wListener();
private final eListener entityListener = new eListener(); private final eListener entityListener = new eListener();
private final sListener serverListener = new sListener();
public static Logger log; public static Logger log;
private Configuration config; private Configuration config;
private PluginManager pm; private PluginManager pm;
@ -91,7 +97,6 @@ public class Stargate extends JavaPlugin {
portalFolder = getDataFolder() + "/portals"; portalFolder = getDataFolder() + "/portals";
gateFolder = getDataFolder() + "/gates/"; gateFolder = getDataFolder() + "/gates/";
log.info(pdfFile.getName() + " v." + pdfFile.getVersion() + " is enabled."); log.info(pdfFile.getName() + " v." + pdfFile.getVersion() + " is enabled.");
pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this);
@ -101,12 +106,9 @@ public class Stargate extends JavaPlugin {
this.migrate(); this.migrate();
this.reloadGates(); this.reloadGates();
if (!this.setupPermissions()) { // Check to see if iConomy/Permissions is loaded yet.
log.info("[Stargate] Permissions not loaded, using defaults"); checkiConomy();
} else { checkPermissions();
if (permissions != null)
log.info("[Stargate] Using Permissions " + permVersion + " (" + Permissions.version + ") for permissions");
}
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
@ -121,6 +123,10 @@ public class Stargate extends JavaPlugin {
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this);
// iConomy Loading
pm.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Priority.Monitor, this);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L);
} }
@ -136,6 +142,13 @@ public class Stargate extends JavaPlugin {
blockMsg = config.getString("other-side-blocked-message", blockMsg); blockMsg = config.getString("other-side-blocked-message", blockMsg);
defNetwork = config.getString("default-gate-network", defNetwork).trim(); defNetwork = config.getString("default-gate-network", defNetwork).trim();
destroyExplosion = config.getBoolean("destroyexplosion", destroyExplosion); destroyExplosion = config.getBoolean("destroyexplosion", destroyExplosion);
// iConomy
iConomyHandler.useiConomy = config.getBoolean("useiconomy", iConomyHandler.useiConomy);
iConomyHandler.createCost = config.getInt("createcost", iConomyHandler.createCost);
iConomyHandler.destroyCost = config.getInt("destroycost", iConomyHandler.destroyCost);
iConomyHandler.useCost = config.getInt("usecost", iConomyHandler.useCost);
iConomyHandler.inFundMsg = config.getString("not-enough-money-message", iConomyHandler.inFundMsg);
saveConfig(); saveConfig();
} }
@ -150,6 +163,13 @@ public class Stargate extends JavaPlugin {
config.setProperty("other-side-blocked-message", blockMsg); config.setProperty("other-side-blocked-message", blockMsg);
config.setProperty("default-gate-network", defNetwork); config.setProperty("default-gate-network", defNetwork);
config.setProperty("destroyexplosion", destroyExplosion); config.setProperty("destroyexplosion", destroyExplosion);
// iConomy
config.setProperty("useiconomy", iConomyHandler.useiConomy);
config.setProperty("createcost", iConomyHandler.createCost);
config.setProperty("destroycost", iConomyHandler.destroyCost);
config.setProperty("usecost", iConomyHandler.useCost);
config.setProperty("not-enough-money-message", iConomyHandler.inFundMsg);
config.save(); config.save();
} }
@ -206,7 +226,9 @@ public class Stargate extends JavaPlugin {
Portal destination = gate.getDestination(); Portal destination = gate.getDestination();
if (!gate.isOpen()) { if (!gate.isOpen()) {
if ((!gate.isFixed()) && gate.isActive() && (gate.getActivePlayer() != player)) { if (iConomyHandler.useiConomy() && iConomyHandler.getBalance(player.getName()) < iConomyHandler.useCost) {
player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg);
} else if ((!gate.isFixed()) && gate.isActive() && (gate.getActivePlayer() != player)) {
gate.deactivate(); gate.deactivate();
if (!denyMsg.isEmpty()) { if (!denyMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + denyMsg); player.sendMessage(ChatColor.RED + denyMsg);
@ -224,37 +246,35 @@ public class Stargate extends JavaPlugin {
player.sendMessage(ChatColor.RED + blockMsg); player.sendMessage(ChatColor.RED + blockMsg);
} }
} else { } else {
gate.open(player, false); gate.open(player, false);
} }
} else { } else {
gate.close(false); gate.close(false);
} }
} }
/* /*
* Find what Permissions plugin we're using and enable it. * Check if iConomy is loaded/enabled already
*/ */
private boolean setupPermissions() { private void checkiConomy() {
Plugin perm; if (!iConomyHandler.useiConomy) return;
perm = pm.getPlugin("Permissions"); Plugin ico = pm.getPlugin("iConomy");
// We're running Permissions if (ico != null && ico.isEnabled()) {
if (perm != null) { iConomyHandler.iConomy = (iConomy)ico;
if (!perm.isEnabled()) { Stargate.log.info("[Stargate] Using iConomy (v" + iConomyHandler.iConomy.getDescription().getVersion() + ")");
pm.enablePlugin(perm); }
} }
permissions = (Permissions)perm;
try { /*
String[] permParts = Permissions.version.split("\\."); * Check if Permissions is loaded/enabled already
permVersion = Double.parseDouble(permParts[0] + "." + permParts[1]); */
} catch (Exception e) { private void checkPermissions() {
log.info("Could not determine Permissions version: " + Permissions.version); Plugin perm = pm.getPlugin("Permissions");
return true; if (perm != null && perm.isEnabled()) {
} permissions = (Permissions)perm;
return true; Stargate.log.info("[Stargate] Using Permissions (v" + permissions.getDescription().getVersion() + ")");
} }
// Permissions not loaded }
return false;
}
/* /*
* Check whether the player has the given permissions. * Check whether the player has the given permissions.
@ -306,11 +326,20 @@ public class Stargate extends JavaPlugin {
Portal destination = portal.getDestination(); Portal destination = portal.getDestination();
if (destination != null) { if (destination != null) {
if (!teleMsg.isEmpty()) { if (!iConomyHandler.useiConomy() || iConomyHandler.chargePlayer(player.getName(), iConomyHandler.useCost)) {
player.sendMessage(ChatColor.BLUE + teleMsg); if (iConomyHandler.useiConomy()) {
} player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(iConomyHandler.useCost));
}
destination.teleport(player, portal, event); if (!teleMsg.isEmpty()) {
player.sendMessage(ChatColor.BLUE + teleMsg);
}
destination.teleport(player, portal, event);
} else {
if (!iConomyHandler.inFundMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg);
}
}
portal.close(false); portal.close(false);
} }
} else { } else {
@ -342,6 +371,12 @@ public class Stargate extends JavaPlugin {
// Initialize a stargate // Initialize a stargate
if (hasPerm(player, "stargate.create", player.isOp()) || if (hasPerm(player, "stargate.create", player.isOp()) ||
hasPerm(player, "stargate.create.personal", false)) { hasPerm(player, "stargate.create.personal", false)) {
if (iConomyHandler.useiConomy() && !iConomyHandler.chargePlayer(player.getName(), iConomyHandler.createCost)) {
if (!iConomyHandler.inFundMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg);
}
return;
}
SignPost sign = new SignPost(new Blox(block)); SignPost sign = new SignPost(new Blox(block));
// Set sign text so we can create a gate with it. // Set sign text so we can create a gate with it.
sign.setText(0, event.getLine(0)); sign.setText(0, event.getLine(0));
@ -351,6 +386,9 @@ public class Stargate extends JavaPlugin {
Portal portal = Portal.createPortal(sign, player); Portal portal = Portal.createPortal(sign, player);
if (portal == null) return; if (portal == null) return;
if (iConomyHandler.useiConomy()) {
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(iConomyHandler.createCost));
}
if (!regMsg.isEmpty()) { if (!regMsg.isEmpty()) {
player.sendMessage(ChatColor.GREEN + regMsg); player.sendMessage(ChatColor.GREEN + regMsg);
} }
@ -423,6 +461,23 @@ public class Stargate extends JavaPlugin {
if (hasPerm(player, "stargate.destroy", player.isOp()) || hasPerm(player, "stargate.destroy.all", player.isOp()) || if (hasPerm(player, "stargate.destroy", player.isOp()) || hasPerm(player, "stargate.destroy.all", player.isOp()) ||
( portal.getOwner().equalsIgnoreCase(player.getName()) && hasPerm(player, "stargate.destroy.owner", false) )) { ( portal.getOwner().equalsIgnoreCase(player.getName()) && hasPerm(player, "stargate.destroy.owner", false) )) {
// Can't afford
if (iConomyHandler.useiConomy() && (iConomyHandler.destroyCost > 0 && iConomyHandler.getBalance(player.getName()) < iConomyHandler.destroyCost)) {
if (!iConomyHandler.inFundMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg);
event.setCancelled(true);
return;
}
}
if (iConomyHandler.useiConomy()) {
iConomyHandler.chargePlayer(player.getName(), iConomyHandler.destroyCost);
if (iConomyHandler.destroyCost > 0) {
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(iConomyHandler.destroyCost));
} else if (iConomyHandler.destroyCost < 0) {
player.sendMessage(ChatColor.GREEN + "Refunded " + iConomy.getBank().format(-iConomyHandler.destroyCost));
}
}
portal.unregister(true); portal.unregister(true);
if (!dmgMsg.isEmpty()) { if (!dmgMsg.isEmpty()) {
player.sendMessage(ChatColor.RED + dmgMsg); player.sendMessage(ChatColor.RED + dmgMsg);
@ -480,6 +535,40 @@ public class Stargate extends JavaPlugin {
} }
} }
private class sListener extends ServerListener {
@Override
public void onPluginEnabled(PluginEvent event) {
if (iConomyHandler.useiConomy && iConomyHandler.iConomy == null) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("iConomy")) {
iConomyHandler.iConomy = (iConomy)event.getPlugin();
Stargate.log.info("[Stargate] Using iConomy (v" + iConomyHandler.iConomy.getDescription().getVersion() + ")");
}
}
if (permissions == null) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("Permissions")) {
permissions = (Permissions)event.getPlugin();
Stargate.log.info("[Stargate] Using Permissions (v" + permissions.getDescription().getVersion() + ")");
}
}
}
@Override
public void onPluginDisabled(PluginEvent event) {
if (iConomyHandler.useiConomy && iConomyHandler.iConomy != null) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("iConomy")) {
iConomyHandler.iConomy = null;
Stargate.log.info("[Stargate] iConomy Disabled");
}
}
if (permissions != null) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("Permissions")) {
permissions = null;
Stargate.log.info("[Stargate] Permissions Disabled");
}
}
}
}
private class SGThread implements Runnable { private class SGThread implements Runnable {
public void run() { public void run() {
long time = System.currentTimeMillis() / 1000; long time = System.currentTimeMillis() / 1000;

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.TheDgtl.Stargate.Stargate main: net.TheDgtl.Stargate.Stargate
version: 0.28 version: 0.29
description: Stargate mod for Bukkit description: Stargate mod for Bukkit
author: Drakia author: Drakia
website: http://www.thedgtl.net website: http://www.thedgtl.net