From 1d897e9d3e8b15f8221823ade62490f115fc2593 Mon Sep 17 00:00:00 2001 From: Zrips Date: Wed, 30 Jan 2019 16:05:46 +0200 Subject: [PATCH] New job action: StripLogs --- .../gamingmesh/jobs/config/ConfigManager.java | 7 +++-- .../jobs/config/LanguageManager.java | 2 ++ .../gamingmesh/jobs/container/ActionType.java | 1 + .../jobs/listeners/JobsPaymentListener.java | 26 +++++++++++++++++-- src/main/resources/jobConfig.yml | 12 ++++++++- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 9f57bc67..10b080ba 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -206,6 +206,7 @@ public class ConfigManager { case CRAFT: case BREW: case BREAK: + case STRIPLOGS: material = CMIMaterial.get(myKey + (subType)); if (material == null) @@ -254,7 +255,7 @@ public class ConfigManager { } // Break and Place actions MUST be blocks - if (actionType == ActionType.BREAK || actionType == ActionType.PLACE) { + if (actionType == ActionType.BREAK || actionType == ActionType.PLACE || actionType == ActionType.STRIPLOGS) { if (!material.isBlock()) { Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + material + "(" + myKey + ")! Material must be a block!"); @@ -969,6 +970,7 @@ public class ConfigManager { case CRAFT: case BREW: case BREAK: + case STRIPLOGS: material = CMIMaterial.get(myKey + (subType)); if (material == null) @@ -1017,7 +1019,7 @@ public class ConfigManager { } // Break and Place actions MUST be blocks - if (actionType == ActionType.BREAK || actionType == ActionType.PLACE) { + if (actionType == ActionType.BREAK || actionType == ActionType.PLACE || actionType == ActionType.STRIPLOGS) { if (!material.isBlock()) { Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid " + actionType.getName() + " type property: " + material + " (" + key + ")! Material must be a block!"); @@ -1134,6 +1136,7 @@ public class ConfigManager { } if (type == null) { + Debug.D("type null"); Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid " + actionType.getName() + " type property: " + key + "!"); continue; } diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 9252d85e..7c480822 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -381,6 +381,8 @@ public class LanguageManager { c.get("command.info.output.tntbreak.none", "%jobname% does not get money for breaking blocks with TNT."); c.get("command.info.output.place.info", "&ePlace"); c.get("command.info.output.place.none", "%jobname% does not get money for placing blocks."); + c.get("command.info.output.striplogs.info", "&eStrip logs"); + c.get("command.info.output.striplogs.none", "%jobname% does not get money for stripping logs."); c.get("command.info.output.kill.info", "&eKill"); c.get("command.info.output.kill.none", "%jobname% does not get money for killing monsters."); c.get("command.info.output.mmkill.info", "&eMMKill"); diff --git a/src/main/java/com/gamingmesh/jobs/container/ActionType.java b/src/main/java/com/gamingmesh/jobs/container/ActionType.java index 8384226a..8c7ccedf 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ActionType.java +++ b/src/main/java/com/gamingmesh/jobs/container/ActionType.java @@ -20,6 +20,7 @@ package com.gamingmesh.jobs.container; public enum ActionType { BREAK("Break"), + STRIPLOGS("StripLogs"), DRINK("Drink"), TNTBREAK("TNTBreak"), PLACE("Place"), diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 66496958..3f2d1cb3 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -47,6 +47,7 @@ import org.bukkit.entity.Tameable; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.enchantment.EnchantItemEvent; @@ -83,6 +84,7 @@ import org.bukkit.projectiles.ProjectileSource; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; +import com.gamingmesh.jobs.CMILib.VersionChecker.Version; import com.gamingmesh.jobs.actions.BlockActionInfo; import com.gamingmesh.jobs.actions.CustomKillInfo; import com.gamingmesh.jobs.actions.EnchantActionInfo; @@ -97,6 +99,7 @@ import com.gamingmesh.jobs.container.ExploreRespond; import com.gamingmesh.jobs.container.FastPayment; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling.ownershipFeedback; import com.google.common.base.Objects; @@ -1438,7 +1441,7 @@ public class JobsPaymentListener implements Listener { if (CMIMaterial.get(block).equals(CMIMaterial.FURNACE) || CMIMaterial.get(block).equals(CMIMaterial.LEGACY_BURNING_FURNACE)) { if (!Jobs.getGCManager().isFurnacesReassign()) - return; + return; ownershipFeedback done = FurnaceBrewingHandling.registerFurnaces(event.getPlayer(), block); if (done.equals(ownershipFeedback.tooMany)) { @@ -1466,7 +1469,7 @@ public class JobsPaymentListener implements Listener { } } else if (CMIMaterial.get(block).equals(CMIMaterial.BREWING_STAND) || CMIMaterial.get(block).equals(CMIMaterial.LEGACY_BREWING_STAND)) { if (!Jobs.getGCManager().isBrewingStandsReassign()) - return; + return; ownershipFeedback done = FurnaceBrewingHandling.registerBrewingStand(event.getPlayer(), block); if (done.equals(ownershipFeedback.tooMany)) { @@ -1492,6 +1495,25 @@ public class JobsPaymentListener implements Listener { "[current]", jPlayer.getBrewingStandCount(), "[max]", jPlayer.getMaxBrewingStandsAllowed() == 0 ? "-" : jPlayer.getMaxBrewingStandsAllowed())); } + } else if (Version.isCurrentEqualOrHigher(Version.v1_13_R1) && + block.getType().toString().endsWith("_LOG") && + !block.getType().toString().startsWith("STRIPPED_") && + event.getAction() == Action.RIGHT_CLICK_BLOCK) { + ItemStack iih = Jobs.getNms().getItemInMainHand(event.getPlayer()); + if (iih.getType().toString().endsWith("_AXE")) { + final Location loc = event.getClickedBlock().getLocation(); + final JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + Block b = loc.getBlock(); + if (b.getType().toString().startsWith("STRIPPED_")) { + Jobs.action(jPlayer, new BlockActionInfo(b, ActionType.STRIPLOGS), b); + } + return; + } + }, 1); + } } } diff --git a/src/main/resources/jobConfig.yml b/src/main/resources/jobConfig.yml index 7d7be6ea..c67587fe 100644 --- a/src/main/resources/jobConfig.yml +++ b/src/main/resources/jobConfig.yml @@ -199,7 +199,17 @@ Jobs: 13: # you can use minuses to take away money if the player break this block income: -1.0 - experience: -1.0 + experience: -1.0 + # payment for stripping wood logs, only for 1.13+ servers + StripLogs: + STRIPPED_ACACIA_LOG: + income: 1.0 + points: 1.0 + experience: 1.0 + STRIPPED_OAK_LOG: + income: 1.0 + points: 1.0 + experience: 1.0 # payment for drinking a potion Drink: potion: