1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

update for better handling for furnace and brewing ownership

new command clearownership
This commit is contained in:
Zrips 2018-01-22 15:46:51 +02:00
parent 8809a33c4e
commit 91763e0bdf
9 changed files with 177 additions and 53 deletions

View File

@ -35,6 +35,7 @@ import com.gamingmesh.jobs.container.JobConditions;
import com.gamingmesh.jobs.container.JobPermission;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.Debug;
public class PermissionHandler {
private Jobs plugin;
@ -45,7 +46,6 @@ public class PermissionHandler {
public void recalculatePermissions(JobsPlayer jPlayer) {
// long time = System.nanoTime();
if (jPlayer == null)
return;
@ -64,10 +64,11 @@ public class PermissionHandler {
}
// Permissions should only apply if we have permission to use jobs in this world
if (hasWorldPermission(player, player.getWorld().getName())) {
if (hasWorldPermission(player)) {
List<JobProgression> progression = jPlayer.getJobProgression();
// calculate new permissions
HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
if (progression.size() == 0) {
Job job = Jobs.getNoneJob();
if (job != null) {
@ -251,6 +252,12 @@ public class PermissionHandler {
return player.hasPermission("jobs.world." + world.toLowerCase());
}
public boolean hasWorldPermission(JobsPlayer player) {
if (player.getPlayer() == null)
return false;
return hasWorldPermission(player, player.getPlayer().getWorld().getName());
}
public boolean hasWorldPermission(JobsPlayer player, String world) {
if (!Jobs.getPermissionManager().hasPermission(player, "jobs.use")) {
return false;

View File

@ -36,7 +36,7 @@ public class PermissionManager {
private enum prm {
// jobs_join_JOBNAME(remade("jobs.join.%JOBNAME%"), 60 * 1000),
// jobs_use(remade("jobs.use"), 60 * 1000),
jobs_use(remade("jobs.use"), 2 * 1000),
// jobs_boost_JOBNAME_money(remade("jobs.boost.%JOBNAME%.money"), 60 * 1000),
// jobs_boost_JOBNAME_exp(remade("jobs.boost.%JOBNAME%.exp"), 60 * 1000),
// jobs_boost_JOBNAME_points(remade("jobs.boost.%JOBNAME%.points"), 60 * 1000),
@ -54,7 +54,7 @@ public class PermissionManager {
jobs_petpay_AMOUNT(remade("jobs.petpay.%AMOUNT%"), 60 * 1000),
jobs_maxfurnaces_AMOUNT(remade("jobs.maxfurnaces.%AMOUNT%"), 2 * 1000),
jobs_maxbrewingstands_AMOUNT(remade("jobs.maxbrewingstands.%AMOUNT%"), 2 * 1000),
// jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 60 * 1000)
jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2 * 1000)
;
private int reload;

View File

@ -168,7 +168,9 @@ public class PlayerManager {
* @param playername
*/
public void playerJoin(Player player) {
JobsPlayer jPlayer = this.playersUUIDCache.get(player.getUniqueId());
if (jPlayer == null || Jobs.getGCManager().MultiServerCompatability()) {
jPlayer = Jobs.getJobsDAO().loadFromDao(player);
jPlayer.loadLogFromDao();
@ -180,6 +182,7 @@ public class PlayerManager {
jPlayer.onConnect();
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
return;
}
@ -323,7 +326,7 @@ public class PlayerManager {
if (logs != null)
jPlayer.setLog(logs);
if (limits != null)
jPlayer.setPaymentLimit(limits);

View File

@ -0,0 +1,42 @@
package com.gamingmesh.jobs.commands.list;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling;
public class clearownership implements Cmd {
@Override
@JobCommand(400)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
JobsPlayer jPlayer = null;
if (args.length >= 1) {
if (!Jobs.hasPermission(sender, "jobs.command.admin.clearownership", true)) {
return true;
}
jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
} else if (sender instanceof Player) {
jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
}
if (jPlayer == null) {
if (args.length >= 1)
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfo"));
else
Jobs.getCommandManager().sendUsage(sender, "clearownership");
return true;
}
int furnace = FurnaceBrewingHandling.clearFurnaces(jPlayer.getPlayerUUID());
int brewing = FurnaceBrewingHandling.clearBrewingStands(jPlayer.getPlayerUUID());
sender.sendMessage(Jobs.getLanguage().getMessage("command.clearownership.output.cleared", "[furnaces]", furnace, "[brewing]", brewing));
return true;
}
}

View File

@ -139,6 +139,9 @@ public class LanguageManager {
c.get("general.error.ingame", "&cYou can use this command only in game!");
c.get("general.error.fromconsole", "&cYou can use this command only from console!");
c.get("general.error.worldisdisabled", "&cYou cant use command in this world!");
c.get("general.error.newFurnaceRegistration", "&eRegistered new ownership for furnace &7[current]&e/&f[max]");
c.get("general.error.newBrewingRegistration", "&eRegistered new ownership for brewing stand &7[current]&e/&f[max]");
c.get("general.error.noFurnaceRegistration", "&cYou reached max furnace count!");
c.get("general.error.noBrewingRegistration", "&cYou reached max brewing stand count!");
@ -427,6 +430,10 @@ public class LanguageManager {
c.get("command.browse.output.chooseJob", "&7&n&oChoose this job");
c.get("command.browse.output.chooseJobHover", "&7Click here to get this job");
c.get("command.clearownership.help.info", "Clear block ownership");
c.get("command.clearownership.help.args", "(playername)");
c.get("command.clearownership.output.cleared", "&2Removed &7[furnaces] &2furnaces and &7[brewing] &2brewing stands");
c.get("command.quests.help.info", "List available quests");
c.get("command.quests.help.args", "(playername)");
c.get("command.quests.error.noquests", "There are no jobs you can join.");

View File

@ -33,6 +33,7 @@ import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling;
import com.gamingmesh.jobs.stuff.Perm;
import com.gamingmesh.jobs.stuff.TimeManage;
@ -943,4 +944,33 @@ public class JobsPlayer {
public void addDoneQuest() {
this.doneQuests++;
}
public int getFurnaceCount() {
return FurnaceBrewingHandling.getTotalFurnaces(this.getPlayerUUID());
}
public int getBrewingStandCount() {
return FurnaceBrewingHandling.getTotalBrewingStands(this.getPlayerUUID());
}
public int getMaxBrewingStandsAllowed() {
Double maxV = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxbrewingstands");
if (maxV == null || maxV == 0)
maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault();
int max = maxV.intValue();
return max;
}
public int getMaxFurnacesAllowed() {
Double maxV = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxfurnaces");
if (maxV == null || maxV == 0)
maxV = (double) Jobs.getGCManager().getFurnacesMaxDefault();
int max = maxV.intValue();
return max;
}
}

View File

@ -259,16 +259,16 @@ public class JobsListener implements Listener {
// make sure plugin is enabled
if (!plugin.isEnabled())
return;
if (!Jobs.getGCManager().MultiServerCompatability())
if (!Jobs.getGCManager().MultiServerCompatability()) {
Jobs.getPlayerManager().playerJoin(event.getPlayer());
else
} else {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
Jobs.getPlayerManager().playerJoin(event.getPlayer());
}
}, 10L);
}
}
// @EventHandler(priority = EventPriority.MONITOR)

View File

@ -97,6 +97,7 @@ 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;
public class JobsPaymentListener implements Listener {
@ -1326,9 +1327,8 @@ public class JobsPaymentListener implements Listener {
if (block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE) {
boolean done = FurnaceBrewingHandling.registerFurnaces(event.getPlayer(), block);
if (!done) {
ownershipFeedback done = FurnaceBrewingHandling.registerFurnaces(event.getPlayer(), block);
if (done.equals(ownershipFeedback.tooMany)) {
boolean report = false;
if (block.hasMetadata(furnaceOwnerMetadata)) {
List<MetadataValue> data = block.getMetadata(furnaceOwnerMetadata);
@ -1345,12 +1345,16 @@ public class JobsPaymentListener implements Listener {
if (report)
Jobs.getActionBar().send(event.getPlayer(), Jobs.getLanguage().getMessage("general.error.noFurnaceRegistration"));
} else if (done.equals(ownershipFeedback.newReg)) {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer());
Jobs.getActionBar().send(event.getPlayer(), Jobs.getLanguage().getMessage("general.error.newFurnaceRegistration",
"[current]", jPlayer.getFurnaceCount(),
"[max]", jPlayer.getMaxFurnacesAllowed() == 0 ? "-" : jPlayer.getMaxFurnacesAllowed()));
}
} else if (block.getType() == Material.BREWING_STAND) {
boolean done = FurnaceBrewingHandling.registerBrewingStand(event.getPlayer(), block);
if (!done) {
ownershipFeedback done = FurnaceBrewingHandling.registerBrewingStand(event.getPlayer(), block);
if (done.equals(ownershipFeedback.tooMany)) {
boolean report = false;
if (block.hasMetadata(brewingOwnerMetadata)) {
List<MetadataValue> data = block.getMetadata(brewingOwnerMetadata);
@ -1367,6 +1371,11 @@ public class JobsPaymentListener implements Listener {
if (report)
Jobs.getActionBar().send(event.getPlayer(), Jobs.getLanguage().getMessage("general.error.noBrewingRegistration"));
} else if (done.equals(ownershipFeedback.newReg)) {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer());
Jobs.getActionBar().send(event.getPlayer(), Jobs.getLanguage().getMessage("general.error.newBrewingRegistration",
"[current]", jPlayer.getBrewingStandCount(),
"[max]", jPlayer.getMaxBrewingStandsAllowed() == 0 ? "-" : jPlayer.getMaxBrewingStandsAllowed()));
}
}
}

View File

@ -17,6 +17,7 @@ import org.bukkit.metadata.MetadataValue;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.config.YmlMaker;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.listeners.JobsPaymentListener;
public class FurnaceBrewingHandling {
@ -127,7 +128,8 @@ public class FurnaceBrewingHandling {
f.saveDefaultConfig();
FileConfiguration config = f.getConfig();
if (Jobs.getGCManager().isFurnacesReassign())
if (Jobs.getGCManager().isFurnacesReassign()) {
config.set("Furnace", null);
for (Entry<UUID, List<blockLoc>> one : furnaceMap.entrySet()) {
String full = "";
@ -143,8 +145,10 @@ public class FurnaceBrewingHandling {
config.set("Furnace." + one.getKey().toString(), full);
}
}
}
if (Jobs.getGCManager().isBrewingStandsReassign())
if (Jobs.getGCManager().isBrewingStandsReassign()) {
config.set("Brewing", null);
for (Entry<UUID, List<blockLoc>> one : brewingMap.entrySet()) {
String full = "";
@ -159,20 +163,21 @@ public class FurnaceBrewingHandling {
if (!full.isEmpty())
config.set("Brewing." + one.getKey().toString(), full);
}
}
f.saveConfig();
}
public static int getTotalFurnaces(Player player) {
List<blockLoc> ls = furnaceMap.get(player.getUniqueId());
public static int getTotalFurnaces(UUID uuid) {
List<blockLoc> ls = furnaceMap.get(uuid);
if (ls == null)
return 0;
return ls.size();
}
public static int getTotalBrewingStands(Player player) {
List<blockLoc> ls = brewingMap.get(player.getUniqueId());
public static int getTotalBrewingStands(UUID uuid) {
List<blockLoc> ls = brewingMap.get(uuid);
if (ls == null)
return 0;
return ls.size();
@ -210,8 +215,8 @@ public class FurnaceBrewingHandling {
public static boolean removeBrewing(Block block) {
UUID uuid = null;
if (block.hasMetadata(JobsPaymentListener.furnaceOwnerMetadata)) {
List<MetadataValue> data = block.getMetadata(JobsPaymentListener.furnaceOwnerMetadata);
if (block.hasMetadata(JobsPaymentListener.brewingOwnerMetadata)) {
List<MetadataValue> data = block.getMetadata(JobsPaymentListener.brewingOwnerMetadata);
if (!data.isEmpty()) {
// only care about first
MetadataValue value = data.get(0);
@ -235,20 +240,21 @@ public class FurnaceBrewingHandling {
}
public static boolean registerFurnaces(Player player, Block block) {
public enum ownershipFeedback {
invalid, tooMany, newReg, old
}
public static ownershipFeedback registerFurnaces(Player player, Block block) {
if (block.getType() != Material.FURNACE && block.getType() != Material.BURNING_FURNACE) {
return false;
return ownershipFeedback.invalid;
}
Double maxV = Jobs.getPermissionManager().getMaxPermission(Jobs.getPlayerManager().getJobsPlayer(player), "jobs.maxfurnaces");
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (maxV == null)
maxV = (double) Jobs.getGCManager().getFurnacesMaxDefault();
int max = jPlayer.getMaxFurnacesAllowed();
int max = maxV.intValue();
int have = getTotalFurnaces(player);
int have = jPlayer.getFurnaceCount();
boolean owner = false;
if (block.hasMetadata(JobsPaymentListener.furnaceOwnerMetadata)) {
@ -259,7 +265,7 @@ public class FurnaceBrewingHandling {
String uuid = value.asString();
if (uuid.equals(player.getUniqueId().toString())) {
if (have > max)
if (have > max && max > 0)
removeFurnace(block);
owner = true;
}
@ -267,10 +273,10 @@ public class FurnaceBrewingHandling {
}
if (owner)
return true;
return ownershipFeedback.old;
if (have >= max && max > 0)
return false;
return ownershipFeedback.tooMany;
block.setMetadata(JobsPaymentListener.furnaceOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), player.getUniqueId().toString()));
@ -280,23 +286,20 @@ public class FurnaceBrewingHandling {
ls.add(new blockLoc(block.getLocation()));
furnaceMap.put(player.getUniqueId(), ls);
return true;
return ownershipFeedback.newReg;
}
public static boolean registerBrewingStand(Player player, Block block) {
public static ownershipFeedback registerBrewingStand(Player player, Block block) {
if (block.getType() != Material.BREWING_STAND) {
return false;
return ownershipFeedback.invalid;
}
Double maxV = Jobs.getPermissionManager().getMaxPermission(Jobs.getPlayerManager().getJobsPlayer(player), "jobs.maxbrewingstands");
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (maxV == null)
maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault();
int max = jPlayer.getMaxBrewingStandsAllowed();
int max = maxV.intValue();
int have = getTotalFurnaces(player);
int have = jPlayer.getBrewingStandCount();
boolean owner = false;
if (block.hasMetadata(JobsPaymentListener.brewingOwnerMetadata)) {
@ -307,18 +310,17 @@ public class FurnaceBrewingHandling {
String uuid = value.asString();
if (uuid.equals(player.getUniqueId().toString())) {
if (have > max)
if (have > max && max > 0)
removeBrewing(block);
owner = true;
}
}
}
if (owner)
return true;
return ownershipFeedback.old;
if (have >= max && max > 0)
return false;
return ownershipFeedback.tooMany;
block.setMetadata(JobsPaymentListener.brewingOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), player.getUniqueId().toString()));
@ -328,16 +330,40 @@ public class FurnaceBrewingHandling {
ls.add(new blockLoc(block.getLocation()));
brewingMap.put(player.getUniqueId(), ls);
return true;
return ownershipFeedback.newReg;
}
public static boolean clearFurnaces(Player player) {
furnaceMap.remove(player.getUniqueId());
return true;
public static int clearFurnaces(UUID uuid) {
List<blockLoc> ls = furnaceMap.remove(uuid);
if (ls == null)
return 0;
for (blockLoc one : ls) {
Block block = one.getBlock();
if (block == null)
continue;
if (block.getType() != Material.FURNACE && block.getType() != Material.BURNING_FURNACE) {
continue;
}
block.removeMetadata(JobsPaymentListener.furnaceOwnerMetadata, Jobs.getInstance());
}
return ls.size();
}
public static boolean clearBrewingStands(Player player) {
brewingMap.remove(player.getUniqueId());
return true;
public static int clearBrewingStands(UUID uuid) {
List<blockLoc> ls = brewingMap.remove(uuid);
if (ls == null)
return 0;
for (blockLoc one : ls) {
Block block = one.getBlock();
if (block == null)
continue;
if (block.getType() != Material.BREWING_STAND) {
continue;
}
block.removeMetadata(JobsPaymentListener.brewingOwnerMetadata, Jobs.getInstance());
}
return ls.size();
}
}