mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 04:25:15 +01:00
Informing about lost ownership
Option to override existing ownerships Option to set range
This commit is contained in:
parent
122ee48197
commit
2c5602ab8b
@ -66,7 +66,7 @@ public class GeneralConfigManager {
|
||||
SoundTitleChangeSound, ServerAccountName, ServertaxesAccountName, localeString = "";
|
||||
private String getSelectionTool, DecimalPlacesMoney, DecimalPlacesExp, DecimalPlacesPoints;
|
||||
|
||||
public int jobExpiryTime, BlockProtectionDays, FireworkPower, ShootTime,
|
||||
public int jobExpiryTime, BlockProtectionDays, FireworkPower, ShootTime, blockOwnershipRange,
|
||||
globalblocktimer, CowMilkingTimer, InfoUpdateInterval, JobsTopAmount, PlaceholdersPage, ConfirmExpiryTime,
|
||||
SegmentCount, BossBarTimer, AutoJobJoinDelay, DBCleaningJobsLvl, DBCleaningUsersDays, BlastFurnacesMaxDefault, SmokersMaxDefault,
|
||||
levelLossPercentageFromMax, levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume,
|
||||
@ -96,7 +96,7 @@ public class GeneralConfigManager {
|
||||
EmptyServerAccountActionBar, ActionBarsMessageByDefault, aBarSilentMode, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment,
|
||||
JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, ShowActionNames, hideItemAttributes,
|
||||
DisableJoiningJobThroughGui, FireworkLevelupUse, UseRandom, UsePerPermissionForLeaving,
|
||||
EnableConfirmation, jobsInfoOpensBrowse, MonsterDamageUse, useMaxPaymentCurve,
|
||||
EnableConfirmation, jobsInfoOpensBrowse, MonsterDamageUse, useMaxPaymentCurve, blockOwnershipTakeOver,
|
||||
hideJobsInfoWithoutPermission, UseTaxes, TransferToServerAccount, TakeFromPlayersPayment, AutoJobJoinUse, AllowDelevel, RomanNumbers,
|
||||
BossBarEnabled = false, BossBarShowOnEachAction = false, BossBarsMessageByDefault = false, ExploreCompact, DBCleaningJobsUse, DBCleaningUsersUse,
|
||||
DisabledWorldsUse, UseAsWhiteListWorldList, PaymentMethodsMoney, PaymentMethodsPoints, PaymentMethodsExp, MythicMobsEnabled,
|
||||
@ -1038,6 +1038,13 @@ public class GeneralConfigManager {
|
||||
tmat = CMIMaterial.get(c.get("JobsGUI.Filler.Material", "GREEN_STAINED_GLASS_PANE"));
|
||||
guiFiller = (tmat == CMIMaterial.NONE ? CMIMaterial.GREEN_STAINED_GLASS_PANE : tmat);
|
||||
|
||||
c.addComment("BlockOwnership.Range", "Set to 0 or lower if you want to disable this. Setting to positive number will mean that player needs to be in this range from owner block to get paid");
|
||||
blockOwnershipRange = c.get("BlockOwnership.Range", 0);
|
||||
|
||||
c.addComment("BlockOwnership.TakeOver", "When enabled by interacting with furncae ownership will get transfered to new player",
|
||||
"If set to false then furnace will belong to player who interacted with it first until its ownership is removed");
|
||||
blockOwnershipTakeOver = c.get("BlockOwnership.TakeOver", false);
|
||||
|
||||
c.save();
|
||||
}
|
||||
|
||||
|
@ -478,6 +478,7 @@ public class LanguageManager {
|
||||
c.get("command.clearownership.help.args", "[playername]");
|
||||
Jobs.getGCManager().getCommandArgs().put("clearownership", Arrays.asList("[playername]"));
|
||||
c.get("command.clearownership.output.cleared", "&2Removed &7[furnaces] &2furnaces, &7[brewing] &2brewing stands, &7[smoker]&2 smokers and &7[blast]&2 blast furnaces.");
|
||||
c.get("command.clearownership.output.lost", "&cLost ownership of &7[type] &cat [location]");
|
||||
|
||||
c.get("command.skipquest.help.info", "Skip defined quest and get new one");
|
||||
c.get("command.skipquest.help.args", "[jobname] [questname] (playerName)");
|
||||
|
@ -9,6 +9,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -23,7 +24,6 @@ import com.gamingmesh.jobs.stuff.blockLoc;
|
||||
|
||||
import net.Zrips.CMILib.Container.CMILocation;
|
||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
|
||||
public class BlockOwnerShip {
|
||||
|
||||
@ -91,13 +91,26 @@ public class BlockOwnerShip {
|
||||
return ownershipFeedback.invalid;
|
||||
}
|
||||
|
||||
HashMap<String, blockLoc> oldRecords = getBlockOwnerShips().get(player.getUniqueId());
|
||||
UUID ownerUUID = this.getOwnerByLocation(block.getLocation());
|
||||
|
||||
if (oldRecords != null) {
|
||||
blockLoc existing = oldRecords.get(CMILocation.toString(block.getLocation(), ":", true, true));
|
||||
if (existing != null) {
|
||||
return ownershipFeedback.old;
|
||||
}
|
||||
if (ownerUUID != null && ownerUUID.equals(player.getUniqueId()))
|
||||
return ownershipFeedback.old;
|
||||
|
||||
if (ownerUUID != null && !ownerUUID.equals(player.getUniqueId())) {
|
||||
if (Jobs.getGCManager().blockOwnershipTakeOver) {
|
||||
// Removing ownership to record new player
|
||||
this.remove(ownerUUID, CMILocation.toString(block.getLocation(), ":", true, true));
|
||||
block.removeMetadata(metadataName, plugin);
|
||||
|
||||
Player owningPlayer = Bukkit.getPlayer(ownerUUID);
|
||||
|
||||
if (owningPlayer != null && owningPlayer.isOnline()) {
|
||||
owningPlayer.sendMessage(Jobs.getLanguage().getMessage("command.clearownership.output.lost", "[type]", CMIMaterial.get(type.toString()).getName(), "[location]", CMILocation.toString(block.getLocation(), ":",
|
||||
true, true)));
|
||||
}
|
||||
|
||||
} else
|
||||
return ownershipFeedback.notOwn;
|
||||
}
|
||||
|
||||
int max = jPlayer.getMaxOwnerShipAllowed(type);
|
||||
@ -106,14 +119,9 @@ public class BlockOwnerShip {
|
||||
boolean owner = false;
|
||||
List<MetadataValue> data = getBlockMetadatas(block);
|
||||
if (!data.isEmpty()) {
|
||||
if (!data.get(0).asString().equals(jPlayer.getUniqueId().toString())) {
|
||||
return ownershipFeedback.notOwn;
|
||||
}
|
||||
|
||||
if (have > max && max > 0) {
|
||||
remove(block);
|
||||
}
|
||||
|
||||
owner = true;
|
||||
}
|
||||
|
||||
@ -205,26 +213,26 @@ public class BlockOwnerShip {
|
||||
|
||||
return ls.size();
|
||||
}
|
||||
|
||||
|
||||
public int remove(UUID uuid, String location) {
|
||||
HashMap<String, blockLoc> ls = blockOwnerShips.get(uuid);
|
||||
if (ls == null)
|
||||
return 0;
|
||||
|
||||
|
||||
for (Entry<String, blockLoc> one : new HashMap<String, blockLoc>(ls).entrySet()) {
|
||||
|
||||
|
||||
if (!one.getKey().equalsIgnoreCase(location))
|
||||
continue;
|
||||
|
||||
|
||||
one.getValue().getBlock().removeMetadata(metadataName, plugin);
|
||||
|
||||
|
||||
ls.remove(one.getKey());
|
||||
|
||||
|
||||
Map<String, UUID> oldRecord = ownerMapByLocation.get(one.getValue().getWorldName());
|
||||
if (oldRecord != null)
|
||||
oldRecord.remove(one.getValue().toVectorString());
|
||||
oldRecord.remove(one.getValue().toVectorString());
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -302,7 +310,7 @@ public class BlockOwnerShip {
|
||||
Map<String, UUID> oldRecord = ownerMapByLocation.getOrDefault(bl.getWorldName(), new HashMap<String, UUID>());
|
||||
oldRecord.put(bl.toVectorString(), uuid);
|
||||
ownerMapByLocation.put(bl.getWorldName(), oldRecord);
|
||||
|
||||
|
||||
total++;
|
||||
}
|
||||
|
||||
|
@ -390,7 +390,13 @@ public final class JobsPaymentListener implements Listener {
|
||||
|
||||
Player player = jPlayer.getPlayer();
|
||||
|
||||
if (player == null || !Jobs.getPermissionHandler().hasWorldPermission(player))
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (Jobs.getGCManager().blockOwnershipRange > 0 && Util.getDistance(player.getLocation(), block.getLocation()) > Jobs.getGCManager().blockOwnershipRange)
|
||||
return;
|
||||
|
||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player))
|
||||
return;
|
||||
|
||||
// check if player is riding
|
||||
@ -1105,9 +1111,12 @@ public final class JobsPaymentListener implements Listener {
|
||||
if (player == null || !player.isOnline())
|
||||
return;
|
||||
|
||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
||||
if (Jobs.getGCManager().blockOwnershipRange > 0 && Util.getDistance(player.getLocation(), block.getLocation()) > Jobs.getGCManager().blockOwnershipRange)
|
||||
return;
|
||||
|
||||
|
||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player))
|
||||
return;
|
||||
|
||||
// check if player is riding
|
||||
if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle())
|
||||
return;
|
||||
|
@ -16,6 +16,7 @@ import java.util.jar.JarFile;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
@ -85,6 +86,17 @@ public final class Util {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public static double getDistance(Location loc1, Location loc2) {
|
||||
if (loc1 == null || loc2 == null || loc1.getWorld() != loc2.getWorld())
|
||||
return Integer.MAX_VALUE;
|
||||
|
||||
try {
|
||||
return loc1.distance(loc2);
|
||||
} catch (Throwable e) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getRealType(Entity entity) {
|
||||
if (Version.isCurrentEqualOrHigher(Version.v1_11_R1)) {
|
||||
return entity.getType().name();
|
||||
|
Loading…
Reference in New Issue
Block a user