Skip to content

Commit

Permalink
Merge pull request #101 from jascotty2/master
Browse files Browse the repository at this point in the history
Update for 1.13/1.14, WorldEdit 7
  • Loading branch information
Mtihc authored May 31, 2019
2 parents f5420e7 + 540128c commit 78b10aa
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 307 deletions.
109 changes: 58 additions & 51 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,60 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mtihc.minecraft.treasurechest.v8.plugin</groupId>
<artifactId>TreasureChest</artifactId>
<version>8.4.5</version>
<name>TreasureChest</name>
<url>http://dev.bukkit.org/server-mods/treasurechest/</url>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<repository>
<id>milkbowl-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>6.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mtihc.minecraft.treasurechest.v8.plugin</groupId>
<artifactId>TreasureChest</artifactId>
<version>8.5</version>
<name>TreasureChest</name>
<url>http://dev.bukkit.org/server-mods/treasurechest/</url>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository><!-- needed for worldedit 7 -->
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<repository>
<id>milkbowl-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Chest;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
Expand Down Expand Up @@ -94,15 +96,15 @@ else if(holder instanceof BlockState) {
}
}

private JavaPlugin plugin;
private final JavaPlugin plugin;
private ITreasureManagerConfiguration config;

private LinkedHashMap<String, TreasureInventory> inventories = new LinkedHashMap<String, TreasureInventory>();
private String permAccessNormal;
private String permAccessUnlimited;
private String permRank;
private final LinkedHashMap<String, TreasureInventory> inventories = new LinkedHashMap();
private final String permAccessNormal;
private final String permAccessUnlimited;
private final String permRank;

private RewardFactoryManager rewardManager;
private final RewardFactoryManager rewardManager;



Expand Down Expand Up @@ -455,85 +457,53 @@ public ITreasureChest getTreasureChest(Block clickedBlock) {
return getTreasure(location);
}

public boolean isBlock(Block block) {

// returns whether the given block would prevent a chest from opening
// based on:
// http://www.minecraftwiki.net/wiki/Chest

if(block == null || block.getType().isTransparent()) {
// translucent/transparent, or non-block
return false;
}
switch (block.getType()) {
// water and lava
case LAVA:
case WATER:
case STATIONARY_LAVA:
case STATIONARY_WATER:

// plants
case LEAVES:
case CACTUS:

// translucent blocks
case GLASS:
case MOB_SPAWNER:
case SNOW:
case ICE:
case FENCE:
case CAKE:
case BED:
case GLOWSTONE:
case ANVIL:
case BEACON:
case CHEST:
case SIGN:
case SIGN_POST:
// slabs
case STEP:
case WOOD_STEP:
// stairs
case WOOD_STAIRS:
case COBBLESTONE_STAIRS:
case BRICK_STAIRS:
case SMOOTH_STAIRS:
case NETHER_BRICK_STAIRS:
case SANDSTONE_STAIRS:
case SPRUCE_WOOD_STAIRS:
case BIRCH_WOOD_STAIRS:
case JUNGLE_WOOD_STAIRS:
case QUARTZ_STAIRS:
return false;
default:
return true;
}
}

public boolean isBlockedByBlockAbove(Block block) {
if(!(block.getState() instanceof InventoryHolder)) {
return false;
}
if(block.getType() != Material.CHEST && block.getType() != Material.ENDER_CHEST && block.getType() != Material.TRAPPED_CHEST) {
return false;
}
InventoryHolder holder = (InventoryHolder) block.getState();
Block above = block.getRelative(BlockFace.UP);
if(holder.getInventory() instanceof DoubleChestInventory) {
DoubleChest dchest = (DoubleChest) holder.getInventory().getHolder();

Block rightSide = ((BlockState)dchest.getRightSide()).getBlock();
Block rightAbove = rightSide.getRelative(BlockFace.UP);
if(isBlock(rightAbove)) {
return true;
}
Block leftSide = ((BlockState)dchest.getLeftSide()).getBlock();
above = leftSide.getRelative(BlockFace.UP);
}

return isBlock(above);
}

Block rightSide;
return block.getRelative(BlockFace.UP).getType().isSolid()
|| ((rightSide = findAdjacentDoubleChest(block)) != null && rightSide.getRelative(BlockFace.UP).getType().isSolid());
}

/**
* Look for a double chest adjacent to a chest
*
* @param block
* @return
*/
public static Block findAdjacentDoubleChest(Block block) {
final BlockData d = block.getBlockData();
if (d instanceof Chest) {
final Chest c = (Chest) d;
if(c.getType() != Chest.Type.SINGLE) {
// this is a double chest - check the other chest for registration data
Block other = null;
switch(c.getFacing()) {
case SOUTH:
other = block.getRelative(c.getType() != Chest.Type.RIGHT ? BlockFace.WEST : BlockFace.EAST);
break;
case NORTH:
other = block.getRelative(c.getType() != Chest.Type.RIGHT ? BlockFace.EAST : BlockFace.WEST);
break;
case EAST:
other = block.getRelative(c.getType() != Chest.Type.RIGHT ? BlockFace.SOUTH : BlockFace.NORTH);
break;
case WEST:
other = block.getRelative(c.getType() != Chest.Type.RIGHT ? BlockFace.NORTH : BlockFace.SOUTH);
}
// double-check
if (other != null && other.getType() == block.getType()) {
return other;
}
}
}
return null;
}

public Set<String> getRanks(ITreasureChest tchest) {
HashSet<String> result = new HashSet<String>();
List<String> chestRanks = tchest.getRanks();
Expand Down Expand Up @@ -659,7 +629,7 @@ private ItemStack[] getRandomizedInventory(ItemStack[] inventory, int randomAmou

// copy inventory to result
ItemStack[] result = new ItemStack[inventory.length];
for (int i = 0; i < inventory.length; i++) {
for (int i = 0; i < inventory.length; ++i) {
result[i] = inventory[i];
}

Expand All @@ -669,7 +639,7 @@ private ItemStack[] getRandomizedInventory(ItemStack[] inventory, int randomAmou

// find indices of non-empty inventory slots
List<Integer> nonNulls = new ArrayList<Integer>();
for (int i = 0; i < inventory.length; i++) {
for (int i = 0; i < inventory.length; ++i) {
if(inventory[i] != null) {
nonNulls.add(i);
}
Expand Down Expand Up @@ -719,7 +689,7 @@ protected void toInventory(ItemStack[] contents, int random, Inventory inventory
}
else {
// add items at correct positions
for (int i = 0; i < tchest.length; i++) {
for (int i = 0; i < tchest.length; ++i) {
result[i] = tchest[i];
}
}
Expand All @@ -732,7 +702,7 @@ protected void toInventory(ItemStack[] contents, int random, Inventory inventory

private static HashSet<Material> getInvisibleBlocks() {
if(invisibleBlocks == null) {
invisibleBlocks = new HashSet<Material>();
invisibleBlocks = new HashSet();
Material[] mats = Material.values();
for (Material mat : mats) {
if(mat.isTransparent()) {
Expand Down Expand Up @@ -933,11 +903,11 @@ public boolean treasureGroupRemove(Player player, Block block, String name, bool

abstract class TreasureInventory implements Runnable {

private JavaPlugin plugin;
private long delay;
private final JavaPlugin plugin;
private final long delay;
private int taskId;

private Inventory inventory;
private final Inventory inventory;

TreasureInventory(JavaPlugin plugin, long delay, Inventory inventory) {
this.plugin = plugin;
Expand Down
Loading

0 comments on commit 78b10aa

Please sign in to comment.