Skip to content

Commit

Permalink
update for bukkit and spot API
Browse files Browse the repository at this point in the history
  • Loading branch information
jascotty2 committed Mar 5, 2012
1 parent c4fba36 commit cd53e22
Show file tree
Hide file tree
Showing 24 changed files with 758 additions and 244 deletions.
3 changes: 3 additions & 0 deletions changelog
Expand Up @@ -2,6 +2,9 @@
BetterShop Changelog: (the (?) means plugin didn't report that as the version.. sorry :))
===============================================================================

Version 2.1.2 - 3/5/12
updated methods for bukkit 1.2.3-R0.2 and SpoutPlugin 474

Version 2.1.1 - 1/27/12
updated register to 1.5 (adds 3co)
added spawn eggs to the shop
Expand Down
7 changes: 2 additions & 5 deletions src/me/jascotty2/bettershop/BSPluginListener.java
Expand Up @@ -31,7 +31,6 @@
import com.jascotty2.minecraftim.MinecraftIM;
import com.nijikokun.bukkit.Permissions.Permissions;
import me.taylorkelly.help.Help;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -110,10 +109,8 @@ public final void checkSpout(Plugin p) {

// spout listeners
PluginManager pm = shop.getServer().getPluginManager();
pm.registerEvent(Event.Type.CUSTOM_EVENT, BetterShop.keyListener,
Event.Priority.Normal, shop);
pm.registerEvent(Event.Type.CUSTOM_EVENT, BetterShop.buttonListener,
Event.Priority.Normal, shop);
pm.registerEvents(BetterShop.keyListener, shop);
pm.registerEvents(BetterShop.buttonListener, shop);

BetterShop.chestShop.registerSpout(true);

Expand Down
7 changes: 2 additions & 5 deletions src/me/jascotty2/bettershop/chestshop/BSChestShop.java
Expand Up @@ -40,7 +40,6 @@
import org.bukkit.block.Chest;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
Expand Down Expand Up @@ -98,9 +97,7 @@ public void registerSpout(boolean enable) {
if (invListen == null) {
invListen = new ChestShopInventoryListenerSpout(this);

plugin.getServer().getPluginManager().
registerEvent(Event.Type.CUSTOM_EVENT, invListen,
Event.Priority.Normal, plugin);
plugin.getServer().getPluginManager().registerEvents(invListen, plugin);
}
} else if (invListen != null) {
invListen = null;
Expand Down Expand Up @@ -178,7 +175,7 @@ public void openChest(Player p, Chest open, boolean isEditing) {
// Get the EntityPlayer handle from the sender
EntityPlayer entityplayer = ((CraftPlayer) p).getHandle();
// open the "chest"
entityplayer.a(chestShop);
entityplayer.openContainer(chestShop);

// save a copy of the chest's current inventory
openPlayers.put(p, ItemStackManip.copy(chestShop.getContents()));
Expand Down
10 changes: 7 additions & 3 deletions src/me/jascotty2/bettershop/chestshop/ChestListener.java
Expand Up @@ -26,14 +26,15 @@
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EndermanPickupEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent;

// end class SignRestore
/**
Expand Down Expand Up @@ -114,8 +115,11 @@ public void onEntityExplode(EntityExplodeEvent event) {
}

@EventHandler(priority = EventPriority.LOW)
public void onEndermanPickup(EndermanPickupEvent event) {
if (!event.isCancelled() && BetterShop.getSettings().signDestroyProtection) {
public void onEntityBlockInteract(EntityInteractEvent event) {
// ought to work for enderman pickup and other break events, but not sure how to test..
if (!event.isCancelled() && event.getBlock() != null
&& !(event.getEntity() instanceof Player)
&& BetterShop.getSettings().signDestroyProtection) {
if (chestsBD.has(event.getBlock().getLocation())) {
event.setCancelled(true);
return;
Expand Down
Expand Up @@ -17,21 +17,23 @@
*/
package me.jascotty2.bettershop.chestshop;

import org.getspout.spoutapi.event.inventory.InventoryCloseEvent;
import org.getspout.spoutapi.event.inventory.InventoryListener;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;

public class ChestShopInventoryListenerSpout extends InventoryListener {
public class ChestShopInventoryListenerSpout implements Listener {

final BSChestShop callback;

public ChestShopInventoryListenerSpout(BSChestShop callback) {
this.callback = callback;
}

@Override
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if ((event.getPlayer() != null)) {
callback.chestClose(event.getPlayer());
callback.chestClose((Player) event.getPlayer());
}
}
} // end class ChestShopPlayerListener
Expand Down
22 changes: 22 additions & 0 deletions src/me/jascotty2/bettershop/chestshop/InventorySmallChest.java
Expand Up @@ -17,9 +17,13 @@
*/
package me.jascotty2.bettershop.chestshop;

import java.util.List;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.IInventory;
import net.minecraft.server.ItemStack;
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.InventoryHolder;

public class InventorySmallChest implements IInventory {
ItemStack items[];String name;
Expand Down Expand Up @@ -108,5 +112,23 @@ public void f() {
public void g() {
}

public ItemStack splitWithoutUpdate(int i) {
throw new UnsupportedOperationException("Not supported yet.");
}

public void onOpen(CraftHumanEntity che) {
}

public void onClose(CraftHumanEntity che) {
}

public List<HumanEntity> getViewers() {
throw new UnsupportedOperationException("Not supported yet.");
}

public InventoryHolder getOwner() {
throw new UnsupportedOperationException("Not supported yet.");
}

} // end class InventorySmallChest

4 changes: 2 additions & 2 deletions src/me/jascotty2/bettershop/shop/BSItemStock.java
Expand Up @@ -122,11 +122,11 @@ public void checkStockRestock() {

public long freeStockRemaining(ItemStack check) {
JItem c = JItemDB.GetItem(check);
return c != null ? freeStockRemaining(c.ID(), c.Data()) : -1;
return c != null ? freeStockRemaining(c.ID(), (byte) c.Data()) : -1;
}

public long freeStockRemaining(JItem check) {
return check != null ? freeStockRemaining(check.ID(), check.Data()) : -1;
return check != null ? freeStockRemaining(check.ID(), (byte) check.Data()) : -1;
}

public long freeStockRemaining(int id, byte dat) {
Expand Down
Binary file modified src/me/jascotty2/bettershop/shop/BSPriceList.java
Binary file not shown.
2 changes: 1 addition & 1 deletion src/me/jascotty2/bettershop/signshop/BSSignShop.java
Expand Up @@ -257,7 +257,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
JItem it = JItemDB.GetItem(ite);
itemN += it.coloredName() + ", ";
total += signInfo.getCustomPrice() >= 0 ? signInfo.getCustomPrice() * ite.getAmount()
: shop.pricelist.itemSellPrice(player, it.ID(), it.Data(), ite.getAmount());
: shop.pricelist.itemSellPrice(player, it.ID(), (byte) it.Data(), ite.getAmount());
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/me/jascotty2/bettershop/signshop/SignRestore.java
Expand Up @@ -26,13 +26,14 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EndermanPickupEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.EntityExplodeEvent;

/**
Expand Down Expand Up @@ -123,9 +124,12 @@ public void onEntityExplode(EntityExplodeEvent event) {
}
}

@EventHandler
public void onEndermanPickup(EndermanPickupEvent event) {
if (!event.isCancelled() && BetterShop.getSettings().signDestroyProtection) {
@EventHandler(priority = EventPriority.LOW)
public void onEntityBlockInteract(EntityInteractEvent event) {
// ought to work for enderman pickup and other break events, but not sure how to test..
if (!event.isCancelled() && event.getBlock() != null
&& !(event.getEntity() instanceof Player)
&& BetterShop.getSettings().signDestroyProtection) {
if (signs.signExists(event.getBlock().getLocation()) || signs.isSignAnchor(event.getBlock())) {
event.setCancelled(true);
return;
Expand Down
10 changes: 4 additions & 6 deletions src/me/jascotty2/bettershop/spout/SpoutKeyListener.java
Expand Up @@ -26,15 +26,13 @@
import me.jascotty2.bettershop.enums.BetterShopPermission;
import me.jascotty2.bettershop.utils.BSPermissions;
import me.jascotty2.bettershop.utils.BetterShopLogger;
import org.getspout.spoutapi.event.input.InputListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.getspout.spoutapi.event.input.KeyPressedEvent;
import org.getspout.spoutapi.gui.ScreenType;
import org.getspout.spoutapi.keyboard.Keyboard;

/**
* @author jacob
*/
public class SpoutKeyListener extends InputListener {
public class SpoutKeyListener implements Listener {

static HashMap<String, String> keys = new HashMap<String, String>();

Expand Down Expand Up @@ -90,7 +88,7 @@ public final void reloadKey() {
}
}

@Override
@EventHandler
public void onKeyPressedEvent(KeyPressedEvent event) {
if (!BetterShop.getSettings().spoutEnabled) {
return;
Expand Down
14 changes: 6 additions & 8 deletions src/me/jascotty2/bettershop/spout/SpoutPopupDisplay.java
Expand Up @@ -471,12 +471,12 @@ public int compare(PriceListItem o1, PriceListItem o2) {
for (PriceListItem p : items) {
ItemButtonContainer m;
if (lg) {
m = new LargeMarketMenuItem(p.ID(), p.Data());
m = new LargeMarketMenuItem(p.ID(), (byte) p.Data());
} else {
m = new SmallMarketMenuItem(p.ID(), p.Data());
m = new SmallMarketMenuItem(p.ID(), (byte) p.Data());
}
m.setEnabled(/*vis*/ false).setY(y).setX(x);//.setWidth(wid).setHeight(hgt);
if(vis) {
m.setEnabled(/*vis*/false).setY(y).setX(x);//.setWidth(wid).setHeight(hgt);
if (vis) {
delayShowList.add(m);
}
menuItems.add(m);
Expand Down Expand Up @@ -524,25 +524,23 @@ public int compare(PriceListItem o1, PriceListItem o2) {
}

}

/* temp fix for a new spout problem .. */
ArrayList<ItemButtonContainer> delayShowList = new ArrayList<ItemButtonContainer>();
java.util.Timer showDelay;

private void startShow() {
showDelay = new java.util.Timer();
showDelay.schedule(new java.util.TimerTask() {

@Override
public void run() {
for(ItemButtonContainer m : delayShowList) {
for (ItemButtonContainer m : delayShowList) {
m.setEnabled(true);
}
delayShowList.clear();
}
}, 100);
}


protected void clearDisplay() {
for (ItemButtonContainer m : menuItems) {
Expand Down
14 changes: 6 additions & 8 deletions src/me/jascotty2/bettershop/spout/SpoutPopupListener.java
Expand Up @@ -18,21 +18,19 @@
package me.jascotty2.bettershop.spout;

import me.jascotty2.bettershop.utils.BetterShopLogger;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.getspout.spoutapi.event.screen.ButtonClickEvent;
import org.getspout.spoutapi.event.screen.ScreenListener;
import org.getspout.spoutapi.event.screen.SliderDragEvent;
import org.getspout.spoutapi.event.screen.TextFieldChangeEvent;

/**
* @author jacob
*/
public class SpoutPopupListener extends ScreenListener {
public class SpoutPopupListener implements Listener {

private boolean buttonError = false,
sliderError = false,
textError = false;

@Override
@EventHandler
public void onButtonClick(ButtonClickEvent event) {
try{
SpoutPopupDisplay d = SpoutPopupDisplay.getPopup(event.getPlayer());
Expand All @@ -45,7 +43,7 @@ public void onButtonClick(ButtonClickEvent event) {
}
}

@Override
@EventHandler
public void onSliderDrag(SliderDragEvent event) {
try {
SpoutPopupDisplay d = SpoutPopupDisplay.getPopup(event.getPlayer());
Expand All @@ -58,7 +56,7 @@ public void onSliderDrag(SliderDragEvent event) {
}
}

@Override
@EventHandler
public void onTextFieldChange(TextFieldChangeEvent event){
try {
SpoutPopupDisplay d = SpoutPopupDisplay.getPopup(event.getPlayer());
Expand Down

1 comment on commit cd53e22

@robxu9
Copy link

@robxu9 robxu9 commented on cd53e22 Mar 6, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still hooking into Register wrong (use Vault, also), using old spout versions (old imports)....

Please sign in to comment.