1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

Lets not remove block ownership on hopper transfer

We will only disable payments for this block until next player
interaction or server restart.
This commit is contained in:
Zrips 2022-03-09 14:25:51 +02:00
parent ba16c1a68e
commit 1f691f448c
6 changed files with 122 additions and 20 deletions

View File

@ -73,9 +73,12 @@ public class ownedblocks implements Cmd {
CMILocation loc = CMILocation.fromString(record.getKey(), ":");
rm.addText(Jobs.getLanguage().getMessage("command.ownedblocks.output.list", "[place]", i, "[type]", material.getName(), "[location]", LC.Location_Full.getLocale((Location) loc)));
rm.addHover(Jobs.getLanguage().getMessage("command.ownedblocks.output.listHover", "[location]", LC.Location_Full.getLocale((Location) loc)));
rm.addCommand(JobsCommands.LABEL + " " + clearownership.class.getSimpleName() + " " + jp.getName() + " " + record.getKey());
if (record.getValue().isDisabled()) {
rm.addText(Jobs.getLanguage().getMessage("command.ownedblocks.output.disabled"));
rm.addHover(Jobs.getLanguage().getMessage("command.ownedblocks.output.disabledHover"));
}
}
}
rm.show(sender);

View File

@ -853,10 +853,10 @@ public class GeneralConfigManager {
}
c.addComment("ExploitProtections.Smelt.PreventHopperFillUps", "Prevent payments when hoppers moving items into furnace", "Player will not get paid, but items will be smelted");
PreventHopperFillUps = c.get("ExploitProtections.Smelt.PreventHopperFillUps", true);
PreventHopperFillUps = c.get("ExploitProtections.Smelt.PreventHopperFillUps", false);
c.addComment("ExploitProtections.Smelt.PreventMagmaCubeSplit", "Prevent payments when hoppers moving items into brewing stands",
"Player will not get paid, but items will be brewd as they supose too");
PreventBrewingStandFillUps = c.get("ExploitProtections.Brew.PreventBrewingStandFillUps", true);
PreventBrewingStandFillUps = c.get("ExploitProtections.Brew.PreventBrewingStandFillUps", false);
c.addComment("use-breeder-finder", "Breeder finder.",
"If you are not using breeding payment, you can disable this to save little resources. Really little.");

View File

@ -101,7 +101,9 @@ public class LanguageManager {
c.get("general.error.worldisdisabled", "&cYou can't use command in this world!");
c.get("general.error.newRegistration", "&eRegistered new ownership for [block] &7[current]&e/&f[max]");
c.get("general.error.reenabledBlock", "&eReenabled ownership");
c.get("general.error.noRegistration", "&cYou've reached max [block] count!");
c.get("general.error.blockDisabled", "&6Payments from &e[type] &6got disabled. &2[location]");
c.get("command.help.output.info", "Type /jobs [cmd] ? for more information about a command.");
c.get("command.help.output.cmdUsage", "&2Usage: &7[command]");
@ -488,6 +490,8 @@ public class LanguageManager {
Jobs.getGCManager().getCommandArgs().put("ownedblocks", Arrays.asList("[playername]"));
c.get("command.ownedblocks.output.list", "&6[place]. &e[type] -> [location]");
c.get("command.ownedblocks.output.listHover", "&6Click to remove: [location]");
c.get("command.ownedblocks.output.disabled", "&6(disabled)");
c.get("command.ownedblocks.output.disabledHover", "&6This block got disabled due to hopper actions");
c.get("command.clearownership.help.info", "Clear block ownership");
c.get("command.clearownership.help.args", "[playername]");

View File

@ -81,6 +81,18 @@ public class BlockOwnerShip {
return blockOwnerShips;
}
public boolean isDisabled(UUID uuid, Location loc) {
HashMap<String, blockLoc> records = getBlockOwnerShips().get(uuid);
if (records == null)
return false;
blockLoc old = records.get(CMILocation.toString(loc, ":", true, true));
if (old == null)
return false;
return old.isDisabled();
}
public ownershipFeedback register(Player player, Block block) {
if (type != BlockTypes.getFromCMIMaterial(CMIMaterial.get(block))) {
return ownershipFeedback.invalid;
@ -93,8 +105,17 @@ public class BlockOwnerShip {
UUID ownerUUID = this.getOwnerByLocation(block.getLocation());
if (ownerUUID != null && ownerUUID.equals(player.getUniqueId()))
if (ownerUUID != null && ownerUUID.equals(player.getUniqueId())) {
HashMap<String, blockLoc> records = getBlockOwnerShips().get(ownerUUID);
if (records != null) {
blockLoc old = records.get(CMILocation.toString(block.getLocation(), ":", true, true));
if (old != null && old.isDisabled()) {
old.setDisabled(false);
return ownershipFeedback.reenabled;
}
}
return ownershipFeedback.old;
}
if (ownerUUID != null && !ownerUUID.equals(player.getUniqueId())) {
if (Jobs.getGCManager().blockOwnershipTakeOver) {
@ -158,6 +179,37 @@ public class BlockOwnerShip {
return ownershipFeedback.newReg;
}
public boolean disable(Block block) {
UUID uuid = getOwnerByLocation(block.getLocation());
if (uuid == null) {
List<MetadataValue> data = getBlockMetadatas(block);
if (!data.isEmpty()) {
try {
uuid = UUID.fromString(data.get(0).asString());
} catch (IllegalArgumentException e) {
}
}
}
if (uuid == null) {
return false;
}
return disable(uuid, block);
}
public boolean disable(UUID uuid, Block block) {
if (uuid == null) {
return false;
}
HashMap<String, blockLoc> ls = blockOwnerShips.getOrDefault(uuid, new HashMap<String, blockLoc>());
String blockLoc = CMILocation.toString(block.getLocation(), ":", true, true);
com.gamingmesh.jobs.stuff.blockLoc record = ls.get(blockLoc);
if (record != null) {
record.setDisabled(true);
return true;
}
return false;
}
public boolean remove(Block block) {
UUID uuid = getOwnerByLocation(block.getLocation());
@ -193,11 +245,11 @@ public class BlockOwnerShip {
}
public UUID getOwnerByLocation(Location loc) {
blockLoc bl = new blockLoc(loc);
Map<String, UUID> record = ownerMapByLocation.get(bl.getWorldName());
Map<String, UUID> record = ownerMapByLocation.get(loc.getWorld().getName());
if (record == null) {
return null;
}
blockLoc bl = new blockLoc(loc);
return record.get(bl.toVectorString());
}
@ -378,6 +430,6 @@ public class BlockOwnerShip {
}
public enum ownershipFeedback {
invalid, tooMany, newReg, old, notOwn
invalid, tooMany, newReg, old, notOwn, reenabled
}
}

View File

@ -128,7 +128,9 @@ import net.Zrips.CMILib.Container.CMILocation;
import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.Version.Version;
public final class JobsPaymentListener implements Listener {
@ -1107,7 +1109,21 @@ public final class JobsPaymentListener implements Listener {
return;
final Block finalBlock = block;
plugin.getBlockOwnerShip(CMIMaterial.get(finalBlock)).ifPresent(os -> os.remove(finalBlock));
plugin.getBlockOwnerShip(CMIMaterial.get(finalBlock)).ifPresent(os -> {
if (os.disable(finalBlock)) {
UUID uuid = plugin.getBlockOwnerShip(CMIMaterial.get(finalBlock)).get().getOwnerByLocation(finalBlock.getLocation());
Player player = Bukkit.getPlayer(uuid);
if (player == null || !player.isOnline())
return;
CMIMessages.sendMessage(player, Jobs.getLanguage().getMessage("general.error.blockDisabled",
"[type]", CMIMaterial.get(finalBlock).getName(),
"[location]", LC.Location_Full.getLocale(finalBlock.getLocation())));
}
});
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -1121,7 +1137,19 @@ public final class JobsPaymentListener implements Listener {
final BrewingStand stand = (BrewingStand) event.getDestination().getHolder();
if (Jobs.getGCManager().canPerformActionInWorld(stand.getWorld()))
plugin.getBlockOwnerShip(CMIMaterial.get(stand.getBlock())).ifPresent(os -> os.remove(stand.getBlock()));
plugin.getBlockOwnerShip(CMIMaterial.get(stand.getBlock())).ifPresent(os -> {
if (os.disable(stand.getBlock())) {
UUID uuid = plugin.getBlockOwnerShip(CMIMaterial.get(stand.getBlock())).get().getOwnerByLocation(stand.getLocation());
Player player = Bukkit.getPlayer(uuid);
if (player == null || !player.isOnline())
return;
CMIMessages.sendMessage(player, Jobs.getLanguage().getMessage("general.error.blockDisabled",
"[type]", CMIMaterial.get(stand.getBlock()).getName(),
"[location]", LC.Location_Full.getLocale(stand.getLocation())));
}
});
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -1162,6 +1190,9 @@ public final class JobsPaymentListener implements Listener {
if (player == null || !player.isOnline())
return;
if (bos.isDisabled(uuid, block.getLocation()))
return;
if (Jobs.getGCManager().blockOwnershipRange > 0 && Util.getDistance(player.getLocation(), block.getLocation()) > Jobs.getGCManager().blockOwnershipRange)
return;
@ -1756,6 +1787,8 @@ public final class JobsPaymentListener implements Listener {
CMIActionBar.send(p, Jobs.getLanguage().getMessage("general.error.newRegistration", "[block]", name,
"[current]", blockOwner.getTotal(jPlayer.getUniqueId()),
"[max]", jPlayer.getMaxOwnerShipAllowed(blockOwner.getType()) == 0 ? "-" : jPlayer.getMaxOwnerShipAllowed(blockOwner.getType())));
} else if (done == ownershipFeedback.reenabled && jPlayer != null) {
CMIActionBar.send(p, Jobs.getLanguage().getMessage("general.error.reenabledBlock"));
}
} else if (!block.getType().toString().startsWith("STRIPPED_") &&
event.getAction() == Action.RIGHT_CLICK_BLOCK && jPlayer != null && hand.toString().endsWith("_AXE")) {

View File

@ -9,8 +9,8 @@ public class blockLoc {
private int x;
private int y;
private int z;
private String worldName;
private World w;
private boolean disabled = false;
public blockLoc(String loc) {
fromString(loc);
@ -21,15 +21,10 @@ public class blockLoc {
y = loc.getBlockY();
z = loc.getBlockZ();
w = loc.getWorld();
worldName = loc.getWorld().getName();
}
public String getWorldName() {
return worldName;
}
public void setWorldName(String worldName) {
this.worldName = worldName;
return w != null ? w.getName() : "__";
}
public void setX(int x) {
@ -46,7 +41,7 @@ public class blockLoc {
@Override
public String toString() {
return (w == null ? worldName : w.getName()) + ":" + x + ":" + y + ":" + z;
return (w == null ? getWorldName() : w.getName()) + ":" + x + ":" + y + ":" + z;
}
public String toVectorString() {
@ -63,7 +58,6 @@ public class blockLoc {
if (w == null)
return false;
this.w = w;
this.worldName = w.getName();
if (split.length < 4) {
return false;
@ -85,11 +79,11 @@ public class blockLoc {
}
public Location getLocation() {
if (worldName == null && w == null)
if (getWorldName() == null && w == null)
return null;
// Make sure cached world is loaded
World w = this.w == null ? Bukkit.getWorld(worldName) : Bukkit.getWorld(this.w.getName());
World w = this.w == null ? Bukkit.getWorld(getWorldName()) : Bukkit.getWorld(this.w.getName());
if (w == null)
return null;
@ -97,4 +91,20 @@ public class blockLoc {
return new Location(w, x, y, z);
}
public boolean isDisabled() {
return disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
public World getWorld() {
return w;
}
public void setWorld(World world) {
this.w = world;
}
}