Skip to content

Commit

Permalink
Fixed softdepend on WorldGuard. CommandShops should once again be usable
Browse files Browse the repository at this point in the history
without WorldGuard, but having WorldGaurd will allow additional
features.
Fixes #5
  • Loading branch information
aeheathc committed Jun 3, 2014
1 parent faf523c commit 83d9f6b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Changelog
* Removed "remove" command. It was always a weird and useless command to take ALL of an item out of your shop even if you don't have inventory space. An accident could be bad if there are too many items to get them back in before they despawn. Remember that you can just use the buy command to take items out of your shop as an owner and it doesn't cost you any money.
* Removed much unused code
* Documented the ItemInfo class after reclassifying it as permanent.
* Fixed softdepend on WorldGuard. CommandShops should once again be usable without WorldGuard, but having WorldGaurd will allow additional features.

**4.2.3**

Expand Down
3 changes: 2 additions & 1 deletion src/com/aehdev/commandshops/CommandShops.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ public void onEnable()
if(Config.REQUIRE_OWNER)
{
log.warning(String.format((Locale)null,"[%s] %s", pdfFile.getName(), "No supported region plugin found, but config says to require owned regions! Existing shops will work but no shops can be created/moved like this."));
}else{
log.info(String.format((Locale)null,"[%s] %s", pdfFile.getName(), "No supported region plugin found, using free selection only."));
}
log.info(String.format((Locale)null,"[%s] %s", pdfFile.getName(), "No supported region plugin found, using free selection only."));
}else{
worldguard = ((WorldGuardPlugin)plugin).getGlobalRegionManager();
log.info(String.format((Locale)null,"[%s] %s", pdfFile.getName(), "WorldGuard support enabled."));
Expand Down
6 changes: 3 additions & 3 deletions src/com/aehdev/commandshops/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.bukkit.entity.Player;

import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

import cuboidLocale.BookmarkedResult;
Expand Down Expand Up @@ -220,13 +219,14 @@ public static void refreshRegionMessages(List<Long> shops)
ProtectedRegion regionobj = CommandShops.worldguard.get(Bukkit.getWorld(world)).getRegion(region);
if(regionobj != null)
{
regionobj.setFlag(DefaultFlag.GREET_MESSAGE, ChatColor.DARK_AQUA + "Entering shop: " + ChatColor.WHITE + shopname);
WGProxy.setGreeting(regionobj, ChatColor.DARK_AQUA + "Entering shop: " + ChatColor.WHITE + shopname);

/*Leaving out exit message for now because worldguard is dumb.
For inner regions with enter/exit messages, when going the opposite direction WG will also play the corresponding message for the OUTER region resulting in twice as many messages as there should be.
Making the inner region have only an enter message means you get 1 going in and 1 going out which is what we want even if only the enter message is actually for the shop and the other one is for the town.
This will never be fixed, they want it that way. This reminder is here to help with integration with other region systems in the future.
*/
//regionobj.setFlag(DefaultFlag.FAREWELL_MESSAGE, ChatColor.DARK_AQUA + "Leaving shop: " + ChatColor.WHITE + shopname);
//WGProxy.setFarewell(regionobj, ChatColor.DARK_AQUA + "Leaving shop: " + ChatColor.WHITE + shopname);
}else{
log.warning(String.format((Locale)null,"[%s] - Shop %d:'%s' has invalid region name %s", CommandShops.pdfFile.getName(), shopid, shopname, region));
}
Expand Down
33 changes: 33 additions & 0 deletions src/com/aehdev/commandshops/WGProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.aehdev.commandshops;

import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

/**
* Quarantine code that causes NoClassDefFoundError simply by having its class loaded when WorldGuard isn't available.
* As long as we don't actually call any method of this class when WorldGuard isn't around, the class doesn't get loaded and everything will work fine.
*/
public class WGProxy
{
/**
* Sets the GREET_MESSAGE flag of a region.
*
* @param regionobj the region object
* @param msg the message
*/
public static void setGreeting(ProtectedRegion regionobj, String msg)
{
regionobj.setFlag(DefaultFlag.GREET_MESSAGE, msg);
}

/**
* Sets the FAREWELL_MESSAGE flag of a region.
*
* @param regionobj the region object
* @param msg the message
*/
public static void setFarewell(ProtectedRegion regionobj, String msg)
{
regionobj.setFlag(DefaultFlag.FAREWELL_MESSAGE, msg);
}
}
7 changes: 3 additions & 4 deletions src/com/aehdev/commandshops/commands/Command.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.aehdev.commandshops.commands;

import java.sql.ResultSet;
import java.util.Arrays;
import java.util.Locale;
import java.util.logging.Logger;

Expand Down Expand Up @@ -268,8 +267,8 @@ protected boolean shopPositionOk(double[] xyzA, double[] xyzB, String worldName)
}

/**
* Check if a theoretical shop position would be acceptable.
* To meet this criteria, it must be in the market if one exists.
* Check if a theoretical shop position would be in a market.
* To meet this criteria, it must overlap a market if one exists.
* @param xyzA
* First of 2 points defining the cuboid
* @param xyzB
Expand All @@ -280,7 +279,7 @@ protected boolean shopPositionOk(double[] xyzA, double[] xyzB, String worldName)
*/
protected boolean shopInMarket(double[] xyzA, double[] xyzB, String worldName)
{
if(Config.MARKETS.length > 0)
if(Config.MARKETS.length > 0 && CommandShops.worldguard != null)
{
boolean good = false;
for(String market : Config.MARKETS)
Expand Down
14 changes: 8 additions & 6 deletions src/com/aehdev/commandshops/commands/CommandShopDestroy.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.aehdev.commandshops.Search;
import com.aehdev.commandshops.Shop;
import com.aehdev.commandshops.ShopLocation;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.aehdev.commandshops.WGProxy;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

import cuboidLocale.BookmarkedResult;
Expand Down Expand Up @@ -78,12 +78,14 @@ public boolean process()
return false;
}

ProtectedRegion regionObj = null;
if(region != null && CommandShops.worldguard != null) regionObj = CommandShops.worldguard.get(Bukkit.getWorld(world)).getRegion(region);
if(regionObj != null)
if(region != null && CommandShops.worldguard != null)
{
regionObj.setFlag(DefaultFlag.GREET_MESSAGE, null);
regionObj.setFlag(DefaultFlag.FAREWELL_MESSAGE, null);
ProtectedRegion regionObj = CommandShops.worldguard.get(Bukkit.getWorld(world)).getRegion(region);
if(regionObj != null)
{
WGProxy.setGreeting(regionObj, null);
WGProxy.setFarewell(regionObj, null);
}
}

String itemQuery = String.format((Locale)null,"SELECT itemid,itemdamage,stock FROM shop_items WHERE shop=%d", shop);
Expand Down
6 changes: 3 additions & 3 deletions src/com/aehdev/commandshops/commands/CommandShopMove.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.aehdev.commandshops.Shop;
import com.aehdev.commandshops.ShopLocation;
import com.aehdev.commandshops.ShopsPlayerListener;
import com.aehdev.commandshops.WGProxy;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

import cuboidLocale.BookmarkedResult;
Expand Down Expand Up @@ -267,8 +267,8 @@ public boolean process()
//update enter/exit messages
if(oldRegion != null)
{
oldRegion.setFlag(DefaultFlag.GREET_MESSAGE, null);
oldRegion.setFlag(DefaultFlag.FAREWELL_MESSAGE, null);
WGProxy.setGreeting(oldRegion, null);
WGProxy.setFarewell(oldRegion, null);
}
if(regionobj != null)
{
Expand Down
5 changes: 3 additions & 2 deletions src/com/aehdev/commandshops/commands/CommandShopSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ public boolean process()
String playerName = player.getName();
World worldobj = player.getWorld();
String world = worldobj.getName();
RegionManager wg = CommandShops.worldguard.get(worldobj);

ShopsPlayerListener.playerRegions.remove(playerName); //cancel region selections

Pattern pattern = Pattern.compile("(?i)select\\s+(.*)");
Matcher matcher = pattern.matcher(command);
if(matcher.find())
if(matcher.find() && CommandShops.worldguard != null)
{
//In this case they used a region name
RegionManager wg = CommandShops.worldguard.get(worldobj);

ShopsPlayerListener.selectingPlayers.remove(playerName); //cancel manual selections
if(CommandShops.worldguard == null)
{
Expand Down

0 comments on commit 83d9f6b

Please sign in to comment.