Skip to content

Commit

Permalink
added register support, added new items
Browse files Browse the repository at this point in the history
  • Loading branch information
jascotty2 committed Mar 13, 2012
1 parent cd53e22 commit fb493e1
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 23 deletions.
8 changes: 8 additions & 0 deletions changelog
Expand Up @@ -2,8 +2,16 @@
BetterShop Changelog: (the (?) means plugin didn't report that as the version.. sorry :))
===============================================================================

Version 2.1.3 - ?
updated chest methods for new bukkit system
added Vault support
added new items


Version 2.1.2 - 3/5/12
updated methods for bukkit 1.2.3-R0.2 and SpoutPlugin 474
note - double chest shops glitch the gui, don't know why


Version 2.1.1 - 1/27/12
updated register to 1.5 (adds 3co)
Expand Down
9 changes: 9 additions & 0 deletions src/itemsdb.yml
Expand Up @@ -956,6 +956,15 @@ items:
item383sub97:
name: Villager Egg
aliases:
item383sub98:
name: Ocelot Egg
aliases: categg
item384:
name: Bottle o' Enchanting
aliases: BottleofEnchanting, experiencebottle, experience
item385:
name: Fire Charge
aliases: fireball
item2256:
name: 13 Disk
aliases: goldrecord, golddisk, grecord, gdisk
Expand Down
54 changes: 48 additions & 6 deletions src/me/jascotty2/bettershop/BSEcon.java
Expand Up @@ -23,22 +23,24 @@
import me.jascotty2.bettershop.enums.EconMethod;
import me.jascotty2.bettershop.utils.BSPermissions;
import me.jascotty2.bettershop.utils.BetterShopLogger;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;

/**
* @author jacob
*/
public class BSEcon implements Listener {

protected static Method economyMethod = null;
protected static Methods _econMethods = new Methods();
protected static String methodName = null;
protected static Economy econ = null;
// iconomy seems to throw alot of errors...
// this is to only display one
static boolean _pastBalanceErr = false;
Expand All @@ -48,11 +50,31 @@ public class BSEcon implements Listener {
public BSEcon(BetterShop plugin) {
BSEcon.plugin = plugin;
pm = plugin.getServer().getPluginManager();
if (setupEconomy()) {
methodName = econ.getName();
BetterShopLogger.Log("Using " + methodName + " (via Vault) for economy");
}
Methods.setMethod(pm);
}

private boolean setupEconomy() {
Plugin v = plugin.getServer().getPluginManager().getPlugin("Vault");
if (!(v instanceof Vault)) {
return false;
}
RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
}

@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
if (econ != null) {
return;
}
if (!Methods.hasMethod() && Methods.setMethod(plugin.getServer().getPluginManager())) {
economyMethod = Methods.getMethod();
methodName = economyMethod.getName() + " v" + economyMethod.getVersion();
Expand All @@ -62,6 +84,9 @@ public void onPluginEnable(PluginEnableEvent event) {

@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
if (econ != null) {
return;
}
// Check to see if the plugin thats being disabled is the one we are using
if (_econMethods != null && Methods.hasMethod() && Methods.checkDisabled(event.getPlugin())) {
economyMethod = null;
Expand All @@ -72,7 +97,7 @@ public void onPluginDisable(PluginDisableEvent event) {
}

public static boolean active() {
return BetterShop.config.econ != EconMethod.AUTO || economyMethod != null;
return BetterShop.config.econ != EconMethod.AUTO || econ != null || economyMethod != null;
}

public static String getMethodName() {
Expand All @@ -87,6 +112,7 @@ public static String getMethodName() {

public static boolean hasAccount(Player pl) {
return pl != null && (BetterShop.config.econ != EconMethod.AUTO
|| (econ != null && econ.hasAccount(pl.getName()))
|| (economyMethod != null && economyMethod.hasAccount(pl.getName())));
}

Expand Down Expand Up @@ -123,7 +149,9 @@ public static double getBalance(String playerName) {
return p == null ? 0 : p.getTotalExperience();
}
try {
if (economyMethod != null && economyMethod.hasAccount(playerName)) {
if (econ != null && econ.hasAccount(playerName)) {
return econ.getBalance(playerName);
} else if (economyMethod != null && economyMethod.hasAccount(playerName)) {
return economyMethod.getAccount(playerName).balance();
}
} catch (Exception e) {
Expand Down Expand Up @@ -161,6 +189,12 @@ public static void addMoney(String playerName, double amt) {
if (pl != null) {
pl.setTotalExperience(pl.getTotalExperience() + (int) amt);
}
} else if (econ != null) {
if (!econ.hasAccount(playerName)) {
// TODO? add methods for creating an account
return;
}
econ.depositPlayer(playerName, amt);
} else if (economyMethod != null) {
if (!economyMethod.hasAccount(playerName)) {
// TODO? add methods for creating an account
Expand Down Expand Up @@ -213,6 +247,12 @@ public static void subtractMoney(String playerName, double amt) {
pl.setTotalExperience(0);
}
}
} else if (econ != null) {
if (!econ.hasAccount(playerName)) {
// TODO? add methods for creating an account
return;
}
econ.withdrawPlayer(playerName, amt);
} else if (economyMethod != null) {
if (!economyMethod.hasAccount(playerName)) {
// TODO? add methods for creating an account
Expand Down Expand Up @@ -318,7 +358,9 @@ private static boolean bankTransaction(String player, double amount) {

public static String format(double amt) {
try {
if (economyMethod != null) {
if (econ != null) {
return econ.format(amt);
} else if (economyMethod != null) {
return economyMethod.format(amt);
}
return String.format("%.2f", amt) + " "
Expand Down
24 changes: 19 additions & 5 deletions src/me/jascotty2/bettershop/BSPluginListener.java
Expand Up @@ -31,23 +31,24 @@
import com.jascotty2.minecraftim.MinecraftIM;
import com.nijikokun.bukkit.Permissions.Permissions;
import me.taylorkelly.help.Help;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.getspout.spout.Spout;

/**
* @author jacob
*/
class BSPluginListener implements Listener {

BetterShop shop;

public BSPluginListener(BetterShop plugin) {
shop = plugin;
PluginManager pm = plugin.getServer().getPluginManager();
checkVaultPermissions(pm.getPlugin("Vault"));
checkPermissions(pm.getPlugin("Permissions"));
checkMIM(pm.getPlugin("MinecraftIM"));
checkSpout(pm.getPlugin("Spout"));
Expand Down Expand Up @@ -86,13 +87,26 @@ public final void checkHelp(Plugin p) {
}
}

public final void checkVaultPermissions(Plugin p) {
if (BSPermissions.vaultPerms == null && p instanceof Vault) {
RegisteredServiceProvider<Permission> rsp = p.getServer().getServicesManager().getRegistration(Permission.class);
if(rsp != null) {
BSPermissions.vaultPerms = rsp.getProvider();
if(BSPermissions.vaultPerms != null) {
BetterShopLogger.Log("Attached to " + BSPermissions.vaultPerms.getName() + " via Vault.");
}
}
}
}

public final void checkPermissions(Plugin p) {
if (BSPermissions.permissionsPlugin == null && p instanceof Permissions) {
if (BSPermissions.vaultPerms == null &&
BSPermissions.permissionsPlugin == null && p instanceof Permissions) {
BSPermissions.permissionsPlugin = (Permissions) p;
BetterShopLogger.Log("Attached to Permissions.");
}
}

public final void checkSpout(Plugin p) {
if (BetterShop.keyListener == null && p instanceof Spout) {

Expand Down
6 changes: 5 additions & 1 deletion src/me/jascotty2/bettershop/utils/BSPermissions.java
Expand Up @@ -22,6 +22,7 @@
import me.jascotty2.bettershop.BetterShop;
import me.jascotty2.bettershop.enums.BetterShopPermission;
import me.jascotty2.lib.util.Str;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -31,6 +32,7 @@
public class BSPermissions {

public static Permissions permissionsPlugin = null;
public static Permission vaultPerms = null;

public static boolean hasPermission(CommandSender player, BetterShopPermission node) {
return hasPermission(player, node.toString(), false);
Expand Down Expand Up @@ -61,7 +63,9 @@ public static boolean hasPermission(CommandSender player, String node, boolean n

public static boolean has(Player player, String node) {
try {
if (permissionsPlugin != null) {
if (vaultPerms != null) {
return vaultPerms.has(player, node);
} else if (permissionsPlugin != null) {
return permissionsPlugin.getHandler().has(player, node);
}
// System.out.println("no perm: checking superperm for " + player.getName() + ": " + node);
Expand Down
24 changes: 15 additions & 9 deletions src/me/jascotty2/lib/bukkit/inventory/ChestManip.java
Expand Up @@ -113,25 +113,31 @@ public synchronized static void setContents(Chest chest, ItemStack iss[], boolea
if(iss.length == 27) {
chest.getInventory().setContents(iss);
} else if (iss.length == 27 * 2) {
ItemStack iss1[] = new ItemStack[27];
ItemStack iss2[] = new ItemStack[27];
System.arraycopy(iss, 0, iss1, 0, iss1.length);
System.arraycopy(iss, 27, iss2, 0, iss2.length);
// new bukkit changed this method completely.. :/
//ItemStack iss1[] = new ItemStack[27];
//ItemStack iss2[] = new ItemStack[27];
//System.arraycopy(iss, 0, iss1, 0, iss1.length);
//System.arraycopy(iss, 27, iss2, 0, iss2.length);

Chest otherChest = otherChest(chest.getBlock());
if (otherChest == null) {
chest.getInventory().setContents(iss1);
//chest.getInventory().setContents(iss1);
chest.getInventory().setContents(iss);
} else {
if (!useOrder || topChest(chest) == chest) {
chest.getInventory().setContents(iss1);
otherChest.getInventory().setContents(iss2);
//chest.getInventory().setContents(iss1);
//otherChest.getInventory().setContents(iss2);
chest.getInventory().setContents(iss);
} else {
otherChest.getInventory().setContents(iss1);
chest.getInventory().setContents(iss2);
//otherChest.getInventory().setContents(iss1);
//chest.getInventory().setContents(iss2);
otherChest.getInventory().setContents(iss);
}
}
}
}


public synchronized static void addContents(Chest chest, ItemStack is) {
Chest otherChest = otherChest(chest.getBlock());
if (otherChest == null) {
Expand Down
1 change: 1 addition & 0 deletions src/me/jascotty2/lib/bukkit/item/JItemDB.java
Expand Up @@ -295,6 +295,7 @@ private static void loadDefaultItems() {
for (Material m : Material.values()) {
String idd = m.getId() + ":0";
if (!items.containsKey(idd)) {
//System.out.println("new item: " + idd + " - " + m.name());
items.put(idd, new JItem(m));
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/me/jascotty2/lib/bukkit/item/JItems.java
Expand Up @@ -188,6 +188,8 @@ public enum JItems {
END_PORTAL_FRAME("End Portal Frame", 120, false),
END_STONE("End Stone", 121, false),
DRAGON_EGG("Dragon Egg", 122, false),
REDSTONE_LAMP_ON("Redstone Lamp ON", 123, false),
REDSTONE_LAMP_OFF("Redstone Lamp", 124, "331@4+89"),
// Items
IRON_SPADE("Iron Shovel", 256, "280@2+265", (short) 251),
IRON_PICKAXE("Iron Pickaxe", 257, "280@2+265@3", (short) 251),
Expand Down Expand Up @@ -389,6 +391,11 @@ public enum JItems {
SPAWN_EGG_MUSHROOMCOW("MushroomCow Egg", 383, (short) 95, false),
SPAWN_EGG_SNOWMAN("SnowMan Egg", 383, (short) 96, false),
SPAWN_EGG_VILLAGER("Villager Egg", 383, (short) 97, false),
SPAWN_EGG_OCELOT("Ocelot Egg", 383, (short) 98, false),
SPAWN_EGG_IRON_GOLEM("Iron Golem Egg", 383, (short) 99, false), // will be added later (not yet implemented in mc)

EXP_BOTTLE("Bottle o' Enchanting", 384, false), // (Experience bottle)
FIREBALL("Fire Charge", 385, "377+289+263=3, 377+289+263:1=3"),

// Records
GOLD_RECORD("13 Disk", 2256, 1), // Gold Record
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.yml
@@ -1,9 +1,9 @@
name: BetterShop
main: me.jascotty2.bettershop.BetterShop
version: 2.1.2
version: 2.1.3
website: http://github.com/BetterShop/BetterShop
author: jascotty2
softdepend: [Spout]
softdepend: [Spout, Vault]
description: >
BetterShop is a global command-based shop for Bukkit.
Supports Permissions, iConomy, BOSEconomy, MultiCurrency,
Expand Down

0 comments on commit fb493e1

Please sign in to comment.