Skip to content

Commit

Permalink
Update Choptree for 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
EpiCanard committed Dec 27, 2018
1 parent a5765dd commit c075917
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 291 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ buildNumber.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar

.vscode
.settings
11 changes: 1 addition & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,11 @@
</repository>
</repositories>
<dependencies>
<!--Spigot API-->
<!--You only need one of the two, don't put both. Spigot is recommended.-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Bukkit API-->
<!--You only need one of the two, don't put both. Spigot is recommended.-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
128 changes: 128 additions & 0 deletions src/main/java/net/gkid117/choptree/BlockFaceEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package net.gkid117.choptree;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;

public enum BlockFaceEnum {

CURRENT(null, null),

N(BlockFace.NORTH, null),
E(BlockFace.EAST, null),
S(BlockFace.SOUTH, null),
W(BlockFace.WEST, null),
NE(BlockFace.NORTH_EAST, null),
NW(BlockFace.NORTH_WEST, null),
SE(BlockFace.SOUTH_EAST, null),
SW(BlockFace.SOUTH_WEST, null),

UP(BlockFace.UP, null),

UP_N(BlockFace.UP, BlockFace.NORTH),
UP_E(BlockFace.UP, BlockFace.EAST),
UP_S(BlockFace.UP, BlockFace.SOUTH),
UP_W(BlockFace.UP, BlockFace.WEST),
UP_NE(BlockFace.UP, BlockFace.NORTH_EAST),
UP_NW(BlockFace.UP, BlockFace.NORTH_WEST),
UP_SE(BlockFace.UP, BlockFace.SOUTH_EAST),
UP_SW(BlockFace.UP, BlockFace.SOUTH_WEST),

DOWN(BlockFace.DOWN, null),
;

private BlockFace faceA;
private BlockFace faceB;

BlockFaceEnum(BlockFace firstFace, BlockFace secondFace) {
this.faceA = firstFace;
this.faceB = secondFace;
}

/**
* Get the block at the specific position from the block
* If ENUM value is UP it will get the block of the block above the block sent in parameter
*
* @param Block Start block position
* @return Block at the specific position from the block
*/
public Block getBlock(Block block) {
if (faceA != null)
block = block.getRelative(this.faceA);
if (faceB != null)
block = block.getRelative(this.faceB);
return block;
}

/**
* Get the material at the specific position from the block
* If ENUM value is UP it will get the material of the block above the block sent in parameter
*
* @param Block Start block position
* @return Material at the specific position from the block
*/
public Material getMaterial(Block block) {
Block bl = this.getBlock(block);
return bl.getType();
}

/**
* Define if the block at the specified face is a wood log block
* If ENUM value is UP it will define if the block above the block sent in parameter is a wodd log
*
* @param Block start block position
* @return Boolean to define if it's a wood log
*/
public Boolean isWood(Block block, ChopTree plugin) {
return plugin.allowedWoodBlocks.contains(this.getMaterial(block).name());
}

/**
* Define if the block at the specified face is a leaf
* If ENUM value is UP it will define if the block above the block sent in parameter is a leaf
*
* @param Block start block position
* @return Boolean to define if it's a leaf
*/
public Boolean isLeaf(Block block, ChopTree plugin) {
return plugin.leavesForDecay.contains(this.getMaterial(block).name());
}

/**
* Define if the block at the specified face is a leaf or a wood
* If ENUM value is UP it will define if the block above the block sent in parameter is a leaf or wood
*
* @param Block start block position
* @return Boolean to define if it's a leaf or wood
*/
public Boolean isLeafOrWood(Block block, ChopTree plugin) {
return this.isLeaf(block, plugin) || this.isWood(block, plugin);
}

/**
* Define if the block at the specified face is the same as material in parameter
* If ENUM value is UP it will define if the block above the block sent in parameter
* is the same as material in parameter
*
* @param Block start block position
* @return Boolean to define if it's the same as in parameter
*/
public Boolean is(Block block, Material material) {
return this.getMaterial(block).equals(material);
}

/**
* Get all the BlockFaceEnum value with first face (faceA) is equal to the param
*
* @param BlockFace value of faceA to compare
* @return List of BlockFaceEnum that has faceA == face
*/
public static List<BlockFaceEnum> getValuesWithFirstFace(BlockFace face) {
final List<BlockFaceEnum> blockFaces = Arrays.asList(BlockFaceEnum.values());
return blockFaces.stream().filter(value -> value.faceA == face).collect(Collectors.toList());
}
}
138 changes: 61 additions & 77 deletions src/main/java/net/gkid117/choptree/ChopTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.logging.Logger;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -32,8 +36,13 @@ public class ChopTree
protected boolean popLeaves;
protected int leafRadius;
protected String[] allowedTools;
protected List<String> allowedWoodBlocks;
protected List<String> leavesForDecay;
private File playerFile;
protected FileConfiguration playersDb;
// Contants.yml
protected List<String> tools;
protected List<String> axes;


public ChopTree() {}
Expand All @@ -58,7 +67,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!");
return false;
}
sender.sendMessage(ChatColor.GOLD + "ChopTree v4.0.1" + getDescription().getVersion() + " : By Gkid117");
sender.sendMessage(ChatColor.GOLD + "ChopTree v" + getDescription().getVersion() + " : By Gkid117 and EpiCanard");
sender.sendMessage(ChatColor.GRAY + "===================================");
sender.sendMessage(ChatColor.GOLD + "ActiveByDefault : " + ChatColor.GRAY + defaultActive);
sender.sendMessage(ChatColor.GOLD + "UseAnything : " + ChatColor.GRAY + useAnything);
Expand All @@ -72,6 +81,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
sender.sendMessage(ChatColor.GOLD + "AllowedTools : " + ChatColor.GRAY + arrayToString(allowedTools, ","));
}
sender.sendMessage(ChatColor.GOLD + "PopLeaves : " + ChatColor.GRAY + popLeaves);
sender.sendMessage(ChatColor.GOLD + "AllowedWoodBlocks : " + ChatColor.GRAY + StringUtils.join(allowedWoodBlocks, ","));
sender.sendMessage(ChatColor.GOLD + "LeavesForDecay : " + ChatColor.GRAY + StringUtils.join(leavesForDecay, ","));
}
else if ((args[0].equalsIgnoreCase("reload")) || (args[0].equalsIgnoreCase("r")))
{
Expand All @@ -96,102 +107,45 @@ else if (args[0].equalsIgnoreCase("toggle"))
sender.sendMessage(ChatColor.RED + "You do not have permission to toggle that setting!");
return false;
}
if (args[1].equalsIgnoreCase("ActiveByDefault"))
{
if (defaultActive)
{
defaultActive = false;
config.set("ActiveByDefault", Boolean.valueOf(false));
}
else
{
defaultActive = true;
config.set("ActiveByDefault", Boolean.valueOf(true));
}
if (args[1].equalsIgnoreCase("ActiveByDefault")){
defaultActive = !defaultActive;
config.set("ActiveByDefault", Boolean.valueOf(defaultActive));
sender.sendMessage(ChatColor.GOLD + "ActiveByDefault set to : " + ChatColor.GRAY + defaultActive);
}
else if (args[1].equalsIgnoreCase("UseAnything"))
{
if (useAnything)
{
useAnything = false;
config.set("UseAnything", Boolean.valueOf(false));
}
else
{
useAnything = true;
config.set("UseAnything", Boolean.valueOf(true));
}
useAnything = !useAnything;
config.set("useAnything", Boolean.valueOf(useAnything));
sender.sendMessage(ChatColor.GOLD + "UseAnything set to : " + ChatColor.GRAY + useAnything);
}
else if (args[1].equalsIgnoreCase("MoreDamageToTools"))
{
if (moreDamageToTools)
{
moreDamageToTools = false;
config.set("MoreDamageToTools", Boolean.valueOf(false));
}
else
{
moreDamageToTools = true;
config.set("MoreDamageToTools", Boolean.valueOf(true));
}
moreDamageToTools = !moreDamageToTools;
config.set("MoreDamageToTools", Boolean.valueOf(moreDamageToTools));
sender.sendMessage(ChatColor.GOLD + "MoreDamageToTools set to : " + ChatColor.GRAY + moreDamageToTools);
}
else if (args[1].equalsIgnoreCase("InterruptIfToolBreaks"))
{
if (interruptIfToolBreaks)
{
interruptIfToolBreaks = false;
config.set("InterruptIfToolBreaks", Boolean.valueOf(false));
}
else
{
interruptIfToolBreaks = true;
config.set("InterruptIfToolBreaks", Boolean.valueOf(true));
}
interruptIfToolBreaks = !interruptIfToolBreaks;
config.set("InterruptIfToolBreaks", Boolean.valueOf(interruptIfToolBreaks));
sender.sendMessage(ChatColor.GOLD + "InterruptIfToolBreaks set to : " + ChatColor.GRAY + interruptIfToolBreaks);
}
else if (args[1].equalsIgnoreCase("LogsMoveDown"))
{
if (logsMoveDown)
{
logsMoveDown = false;
config.set("LogsMoveDown", Boolean.valueOf(false));
}
else
{
logsMoveDown = true;
config.set("LogsMoveDown", Boolean.valueOf(true));
}
logsMoveDown = !logsMoveDown;
config.set("LogsMoveDown", Boolean.valueOf(logsMoveDown));
sender.sendMessage(ChatColor.GOLD + "LogsMoveDown set to : " + ChatColor.GRAY + logsMoveDown);
}
else if (args[1].equalsIgnoreCase("OnlyTrees"))
{
if (onlyTrees)
{
onlyTrees = false;
config.set("OnlyTrees", Boolean.valueOf(false));
}
else
{
onlyTrees = true;
config.set("OnlyTrees", Boolean.valueOf(true));
}
onlyTrees = !onlyTrees;
config.set("OnlyTrees", Boolean.valueOf(onlyTrees));
sender.sendMessage(ChatColor.GOLD + "OnlyTrees set to : " + ChatColor.GRAY + onlyTrees);
}
else if (args[1].equalsIgnoreCase("PopLeaves"))
{
if (popLeaves)
{
popLeaves = false;
config.set("PopLeaves", Boolean.valueOf(false));
}
else
{
popLeaves = true;
config.set("PopLeaves", Boolean.valueOf(true));
}
popLeaves = !popLeaves;
config.set("PopLeaves", Boolean.valueOf(popLeaves));
sender.sendMessage(ChatColor.GOLD + "PopLeaves set to : " + ChatColor.GRAY + popLeaves);
}
else
Expand Down Expand Up @@ -234,13 +188,19 @@ private String arrayToString(String[] array, String separator)

public void loadConfig()
{

// LOAD CONSTANTS
YamlConfiguration constants = YamlConfiguration.loadConfiguration(new InputStreamReader(getResource("constants.yml")));
tools = constants.getStringList("Tools");
axes = constants.getStringList("Axes");

reloadConfig();
config = getConfig();
defaultActive = config.getBoolean("ActiveByDefault", true);
config.set("ActiveByDefault", Boolean.valueOf(defaultActive));
useAnything = config.getBoolean("UseAnything", false);
config.set("UseAnything", Boolean.valueOf(useAnything));
allowedTools = config.getString("AllowedTools", "WOOD_AXE,STONE_AXE,IRON_AXE,GOLD_AXE,DIAMOND_AXE").split(",");
allowedTools = config.getString("AllowedTools").split(",");
config.set("AllowedTools", arrayToString(allowedTools, ","));
moreDamageToTools = config.getBoolean("MoreDamageToTools", false);
config.set("MoreDamageToTools", Boolean.valueOf(moreDamageToTools));
Expand All @@ -254,8 +214,32 @@ public void loadConfig()
config.set("PopLeaves", Boolean.valueOf(popLeaves));
leafRadius = config.getInt("LeafRadius", 3);
config.set("LeafRadius", Integer.valueOf(leafRadius));

allowedWoodBlocks = filterConfigParams("AllowedWoodBlocks", "LOG");
leavesForDecay = filterConfigParams("LeavesForDecay", "LEAVES");

saveConfig();
}

private List<String> filterConfigParams(String configVar, String contain) {
final List<String> input = Arrays.asList(config.getString(configVar).split(","));
final List<String> notAllowed = new ArrayList<>();
final List<String> output = input.stream().filter(block -> {
final Boolean ret = block.contains(contain);
if (!ret)
notAllowed.add(block);
return ret;
}).collect(Collectors.toList());

if(!notAllowed.isEmpty()) {
getLogger().warning("[CONFIG] Those following " + configVar + " are not " + contain + " blocks : " + StringUtils.join(notAllowed, ','));
getLogger().warning("[CONFIG] Config has been rewritten with only those blocks : " + configVar + " = " + StringUtils.join(output, ","));
}

config.set(configVar, StringUtils.join(output, ","));

return output;
}

public void loadPlayers()
{
Expand Down
Loading

0 comments on commit c075917

Please sign in to comment.