@ -1,18 +1,30 @@
package sig.plugin.TwosideKeeper.HelperStructures ;
package sig.plugin.TwosideKeeper.HelperStructures ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.List ;
import java.util.List ;
import org.bukkit.ChatColor ;
import org.bukkit.ChatColor ;
import org.bukkit.Location ;
import org.bukkit.Material ;
import org.bukkit.Material ;
import org.bukkit.block.Block ;
import org.bukkit.block.Sign ;
import org.bukkit.block.Sign ;
import org.bukkit.enchantments.Enchantment ;
import org.bukkit.enchantments.Enchantment ;
import org.bukkit.entity.Entity ;
import org.bukkit.entity.EntityType ;
import org.bukkit.entity.Item ;
import org.bukkit.entity.Player ;
import org.bukkit.entity.Player ;
import org.bukkit.event.player.PlayerInteractEvent ;
import org.bukkit.inventory.ItemStack ;
import org.bukkit.inventory.ItemStack ;
import org.bukkit.inventory.meta.EnchantmentStorageMeta ;
import org.bukkit.inventory.meta.EnchantmentStorageMeta ;
import org.bukkit.material.MaterialData ;
import org.bukkit.material.MaterialData ;
import org.bukkit.potion.PotionType ;
import org.bukkit.potion.PotionType ;
import org.bukkit.util.Vector ;
import com.google.common.collect.Iterables ;
import sig.plugin.TwosideKeeper.Artifact ;
import sig.plugin.TwosideKeeper.TwosideKeeper ;
import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions ;
import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions ;
public class WorldShop {
public class WorldShop {
@ -20,13 +32,15 @@ public class WorldShop {
String owner ;
String owner ;
double price ;
double price ;
int amt ;
int amt ;
int storedamt = 0 ;
int id ;
int id ;
public WorldShop ( ItemStack i , int amt , double p , String player , int shopID ) {
public WorldShop ( ItemStack i , int amt , int storedamt , double p , String player , int shopID ) {
this . item = i ;
this . item = i ;
this . price = p ;
this . price = p ;
this . owner = player ;
this . owner = player ;
this . amt = amt ;
this . amt = amt ;
this . storedamt = storedamt ;
this . id = shopID ;
this . id = shopID ;
}
}
@ -38,9 +52,15 @@ public class WorldShop {
return GenericFunctions . UserFriendlyMaterialName ( this . item ) ;
return GenericFunctions . UserFriendlyMaterialName ( this . item ) ;
}
}
}
}
public int GetStoredAmount ( ) {
return this . storedamt ;
}
public void UpdateAmount ( int amt ) {
public void UpdateAmount ( int amt ) {
this . amt = amt ;
this . amt = amt ;
}
}
public void UpdateStoredAmount ( int newamt ) {
this . storedamt = newamt ;
}
public void UpdateUnitPrice ( double price ) {
public void UpdateUnitPrice ( double price ) {
this . price = price ;
this . price = price ;
}
}
@ -66,7 +86,7 @@ public class WorldShop {
}
}
public String toString ( ) {
public String toString ( ) {
return "WorldShop:{Item:" + item . toString ( ) + ",Price:" + price + ",Amount:" + amt + ",Owner:" + owner + "}" ;
return "WorldShop:{Item:" + item . toString ( ) + ",Price:" + price + ",Amount:" + amt + ",Stored Amount:" + storedamt + ", Owner:" + owner + "}" ;
}
}
public static String GetItemInfo ( ItemStack item ) {
public static String GetItemInfo ( ItemStack item ) {
@ -94,6 +114,47 @@ public class WorldShop {
}
}
}
}
if ( item . getType ( ) . toString ( ) . contains ( "RECORD" ) ) {
switch ( item . getType ( ) ) {
case GREEN_RECORD : {
message + = ChatColor . GRAY + "\nC418 - cat" ;
} break ;
case GOLD_RECORD : {
message + = ChatColor . GRAY + "\nC418 - 13" ;
} break ;
case RECORD_3 : {
message + = ChatColor . GRAY + "\nC418 - blocks" ;
} break ;
case RECORD_4 : {
message + = ChatColor . GRAY + "\nC418 - chirp" ;
} break ;
case RECORD_5 : {
message + = ChatColor . GRAY + "\nC418 - far" ;
} break ;
case RECORD_6 : {
message + = ChatColor . GRAY + "\nC418 - mall" ;
} break ;
case RECORD_7 : {
message + = ChatColor . GRAY + "\nC418 - melohi" ;
} break ;
case RECORD_8 : {
message + = ChatColor . GRAY + "\nC418 - stal" ;
} break ;
case RECORD_9 : {
message + = ChatColor . GRAY + "\nC418 - strad" ;
} break ;
case RECORD_10 : {
message + = ChatColor . GRAY + "\nC418 - ward" ;
} break ;
case RECORD_11 : {
message + = ChatColor . GRAY + "\nC418 - 11" ;
} break ;
case RECORD_12 : {
message + = ChatColor . GRAY + "\nC418 - wait" ;
} break ;
}
}
if ( item . getType ( ) . toString ( ) . contains ( "HELMET" ) | |
if ( item . getType ( ) . toString ( ) . contains ( "HELMET" ) | |
item . getType ( ) . toString ( ) . contains ( "CHESTPLATE" ) | |
item . getType ( ) . toString ( ) . contains ( "CHESTPLATE" ) | |
item . getType ( ) . toString ( ) . contains ( "LEGGINGS" ) | |
item . getType ( ) . toString ( ) . contains ( "LEGGINGS" ) | |
@ -347,11 +408,78 @@ public class WorldShop {
}
}
}
}
public static boolean IsWorldSign ( Sign s ) {
public static boolean isWorldShopSign ( Sign s ) {
if ( s . getLine ( 0 ) . equalsIgnoreCase ( ChatColor . BLUE + "-- SHOP --" ) ) {
if ( s . getLine ( 0 ) . equalsIgnoreCase ( ChatColor . BLUE + "-- SHOP --" ) | |
s . getLine ( 0 ) . equalsIgnoreCase ( ChatColor . BLUE + "- BUYING SHOP -" ) ) {
return true ;
return true ;
} else {
} else {
return false ;
return false ;
}
}
}
}
public static boolean hasShopSignAttached ( Block b ) {
//Returns true if there is a shop sign attached to this block.
//Look on all four sides relative to this block.
TwosideKeeper . log ( "Reference block is " + b . getLocation ( ) . toString ( ) + " of type " + b . getType ( ) , 5 ) ;
for ( int x = - 1 ; x < = 1 ; x + + ) {
for ( int z = - 1 ; z < = 1 ; z + + ) {
if ( ( x ! = 0 | | z ! = 0 ) & & Math . abs ( x ) ! = Math . abs ( z ) ) {
Block checkblock = b . getRelative ( x , 0 , z ) ;
TwosideKeeper . log ( "This is a " + checkblock . getType ( ) , 5 ) ;
if ( checkblock . getType ( ) = = Material . WALL_SIGN ) {
org . bukkit . material . Sign s = ( org . bukkit . material . Sign ) ( checkblock . getState ( ) . getData ( ) ) ;
//See if this sign is "facing" this block.
TwosideKeeper . log ( "Checked block is a " + checkblock . getRelative ( s . getAttachedFace ( ) ) . getType ( ) + " at Loc " + checkblock . getRelative ( s . getAttachedFace ( ) ) . getLocation ( ) . toString ( ) , 4 ) ;
if ( checkblock . getRelative ( s . getAttachedFace ( ) ) . equals ( b ) ) {
TwosideKeeper . log ( "This is the block on the sign! Proceed." , 5 ) ;
//See if this sign is a world shop.
if ( WorldShop . isWorldShopSign ( ( Sign ) checkblock . getState ( ) ) ) {
return true ;
}
}
}
}
}
}
return false ;
}
public static void spawnShopItem ( PlayerInteractEvent ev , Location loc , WorldShop shop ) {
//See if a drop entity is already here.
boolean item_here = false ;
Collection < Entity > entities = ev . getPlayer ( ) . getLocation ( ) . getWorld ( ) . getNearbyEntities ( loc , 1 , 1 , 1 ) ;
for ( int i = 0 ; i < entities . size ( ) ; i + + ) {
Entity e = Iterables . get ( entities , i ) ;
TwosideKeeper . log ( "Entity Location:" + e . getLocation ( ) . toString ( ) , 5 ) ;
TwosideKeeper . log ( "Comparing locations: " + e . getLocation ( ) . toString ( ) + ":::" + loc . toString ( ) , 5 ) ;
if ( e . getType ( ) = = EntityType . DROPPED_ITEM ) {
Item it = ( Item ) e ;
if (
it . getItemStack ( ) . getType ( ) = = shop . GetItem ( ) . getType ( ) & &
it . getItemStack ( ) . getDurability ( ) = = shop . GetItem ( ) . getDurability ( ) & &
it . getCustomName ( ) ! = null & &
it . getCustomName ( ) . equalsIgnoreCase ( "" + shop . getID ( ) ) & &
Math . abs ( e . getLocation ( ) . getX ( ) - loc . getX ( ) ) < = 1 & &
Math . abs ( e . getLocation ( ) . getZ ( ) - loc . getZ ( ) ) < = 1 & &
Math . abs ( e . getLocation ( ) . getY ( ) - loc . getY ( ) ) < = 1
) {
item_here = true ;
}
}
}
if ( ! item_here ) {
TwosideKeeper . log ( "Spawning item!" , 5 ) ;
ItemStack i = shop . GetItem ( ) . clone ( ) ;
ItemStack drop = Artifact . convert ( i ) ;
drop . removeEnchantment ( Enchantment . LUCK ) ;
Item it = ev . getPlayer ( ) . getWorld ( ) . dropItemNaturally ( ev . getClickedBlock ( ) . getLocation ( ) . add ( - ev . getBlockFace ( ) . getModX ( ) + 0 . 5 , - ev . getBlockFace ( ) . getModY ( ) + 1 . 5 , - ev . getBlockFace ( ) . getModZ ( ) + 0 . 5 ) , drop ) ;
it . setPickupDelay ( 999999999 ) ;
it . setVelocity ( new Vector ( 0 , 0 , 0 ) ) ;
it . setCustomName ( "" + shop . getID ( ) ) ;
it . setCustomNameVisible ( false ) ;
it . setInvulnerable ( true ) ;
//it.setGlowing(true);
it . teleport ( ev . getClickedBlock ( ) . getLocation ( ) . add ( - ev . getBlockFace ( ) . getModX ( ) + 0 . 5 , - ev . getBlockFace ( ) . getModY ( ) + 1 . 5 , - ev . getBlockFace ( ) . getModZ ( ) + 0 . 5 ) ) ;
}
}
}
}