Skip to content

Commit

Permalink
Added a "/treechopper reward <amount>" and fixed reset range issue (m…
Browse files Browse the repository at this point in the history
…oved from 8 to 5 blocks [-3])
  • Loading branch information
MrFiend179 committed May 6, 2024
1 parent 67f974c commit 6092d2e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,21 @@ Make tree chopping rewarding in Minecraft servers with this plugin. This is a si
- **Description:** Stops the TreeChop plugin completely.
- **Usage:** `/treechopper forcestop`

### 4 /treechopper worldname <world_name>
### 4 /treechopper worldname [world_name]
- **Description:** Sets the name of the world in which plugin will work.
- **Usage:** `/treechopper worldname <world_name>`
#### 4.1 example:
- 4.1.1 `/treechopper worldname lobby` sets world in which plugin will work to **lobby**
- 4.1.2 `/treechopper worldname world` sets world in which plugin will work to **world**
- 4.1.3 `/treechopper worldname myworld` sets world in which plugin will work to **myworld**

### 5 /treechopper reward [amount]
- **Description:** Sets the amount of money Players will receive.
- **Usage:** `/treechopper reward <amount>`
#### 5.1 example:
- 5.1.1 `/treechopper reward 50` sets the reward amount player will receive to **50**
- 5.1.2 `/treechopper reward 150` sets the reward amount player will receive to **150**

# Permission
You need to use a permissions plugin such as luckperms to handle permission otherwise it won't work.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>mc.treechop</groupId>
<artifactId>TreeChop</artifactId>
<version>1.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>

<name>TreeChop</name>
Expand Down
37 changes: 27 additions & 10 deletions src/main/java/mc/treechop/treechop/TreeChop.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public final class TreeChop extends JavaPlugin implements Listener {
private boolean isEnabled = true;
private String worldName = "";
private int rewardAmount = 50;
private final Map<Location, Integer> pillarCounters = new HashMap<>();
private final Map<Location, Set<Location>> fallenLeavesMap = new HashMap<>();
private final Map<Location, Set<Location>> fallenLogsMap = new HashMap<>();
Expand All @@ -34,7 +35,7 @@ public final class TreeChop extends JavaPlugin implements Listener {
public void onEnable() {
getLogger().info("###############################################");
getLogger().info("# #");
getLogger().info("# Tree Chopper v1.0 #");
getLogger().info("# Tree Chopper v1.0.1 #");
getLogger().info("# Status: Started #");
getLogger().info("# Made by Fiend #");
getLogger().info("# #");
Expand All @@ -48,7 +49,7 @@ public void onEnable() {
public void onDisable() {
getLogger().info("###############################################");
getLogger().info("# #");
getLogger().info("# Tree Chopper v1.0 #");
getLogger().info("# Tree Chopper v1.0.1 #");
getLogger().info("# Status: Stopped #");
getLogger().info("# Made by Fiend #");
getLogger().info("# #");
Expand All @@ -60,7 +61,7 @@ public void onDisable() {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("treechopper")) {
if (args.length == 0) {
sender.sendMessage("Usage: /treechopper <enable|disable|worldname>");
sender.sendMessage("Usage: /treechopper <enable|disable|worldname|reward>");
return true;
}

Expand Down Expand Up @@ -89,8 +90,21 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage("Usage: /treechopper worldname <name>");
}
break;
case "reward":
if (args.length >= 2) {
try {
rewardAmount = Integer.parseInt(args[1]);
sender.sendMessage("§a§l| §aTreeChopper reward amount set to: §6§l" + rewardAmount);
saveConfig();
} catch (NumberFormatException e) {
sender.sendMessage("Please provide a valid number for the reward amount.");
}
} else {
sender.sendMessage("Usage: /treechopper reward <amount>");
}
break;
default:
sender.sendMessage("Usage: /treechopper <enable|disable|worldname>");
sender.sendMessage("Usage: /treechopper <enable|disable|worldname|reward>");
}
return true;
}
Expand All @@ -106,7 +120,7 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String alia
String input = args[0].toLowerCase();

// Add subcommand suggestions based on input
List<String> subCommands = Arrays.asList("enable", "disable", "forcestop", "worldname");
List<String> subCommands = Arrays.asList("enable", "disable", "forcestop", "worldname", "reward");
for (String subCommand : subCommands) {
if (subCommand.startsWith(input)) {
suggestions.add(subCommand);
Expand All @@ -127,7 +141,7 @@ public void onBlockBreak(BlockBreakEvent event) {
World world = event.getBlock().getWorld();
String eventName = worldName.equalsIgnoreCase(world.getName()) ? worldName : "default";

if(!event.getPlayer().hasPermission("TreeChopper.ChopRewards")){
if(!event.getPlayer().hasPermission("TreeChopper.ChopRewards") && isLog(block.getType()) && world.getName().equalsIgnoreCase(eventName)){
event.getPlayer().sendMessage("§c§l| You don't have permission to do this.");
return;
}
Expand All @@ -149,9 +163,10 @@ public void onBlockBreak(BlockBreakEvent event) {
event.getBlock().setType(Material.SPRUCE_LOG);
}, 2);
if (counter == 0) {
// event.getPlayer().sendMessage("§a§l| §aYou received 100$ for Chopping a tree.");
String Player = event.getPlayer().getName();
getServer().dispatchCommand(getServer().getConsoleSender(), "eco give " + Player + " 60");
int rewardamountplr = rewardAmount;
getServer().dispatchCommand(getServer().getConsoleSender(), "eco give " + Player + " " + rewardamountplr);
// getServer().dispatchCommand(getServer().getConsoleSender(), "eco give " + Player + " 60");
pillarCounters.remove(bottomLocation);


Expand Down Expand Up @@ -211,7 +226,7 @@ public void onBlockBreak(BlockBreakEvent event) {
}
}
}
int radiusclr = 8;
int radiusclr = 5;
getServer().getScheduler().runTaskLater(this, () -> {
for (int xOffset = -radiusclr; xOffset <= radiusclr; xOffset++) {
for (int yOffset = -height; yOffset <= height; yOffset++) {
Expand Down Expand Up @@ -365,15 +380,17 @@ private void loadConfig() {
FileConfiguration config = getConfig();
isEnabled = config.getBoolean("enabled", true);
worldName = config.getString("worldName", "lobby");
rewardAmount = config.getInt("rewardAmount", 50); // Load reward amount with default value
}

public void saveConfig() {
FileConfiguration config = getConfig();
config.set("enabled", isEnabled);
config.set("worldName", worldName);
config.set("rewardAmount", rewardAmount);

try {
config.save(getDataFolder() + File.separator + "config.yml");
config.save(new File(getDataFolder(), "config.yml"));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enabled: true
worldName: lobby
rewardAmount: 50

0 comments on commit 6092d2e

Please sign in to comment.