1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-06 16:27:59 +01:00

Improve furnace and hopper saving

- Fixed database syntax issue when getting the global top list
This commit is contained in:
montlikadani 2020-02-22 12:43:02 +01:00
parent f1b1ba48e4
commit ea3cc04998
4 changed files with 34 additions and 45 deletions

17
pom.xml
View File

@ -79,7 +79,7 @@
<dependency> <dependency>
<groupId>com.sk89q.worldguard</groupId> <groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId> <artifactId>worldguard-bukkit</artifactId>
<version>7.0.1-SNAPSHOT</version> <version>7.0.2-SNAPSHOT</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
@ -107,21 +107,6 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-core</artifactId>
<version>7.1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>bukkit-classloader-check</artifactId>
<groupId>org.sk89q.bukkit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId> <artifactId>placeholderapi</artifactId>

View File

@ -1635,11 +1635,14 @@ public abstract class JobsDAO {
*/ */
public List<TopList> getGlobalTopList(int start) { public List<TopList> getGlobalTopList(int start) {
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
List<TopList> names = new ArrayList<>(); List<TopList> names = new ArrayList<>();
if (conn == null) if (conn == null)
return names; return names;
if (start < 0) {
start = 0;
}
PreparedStatement prest = null; PreparedStatement prest = null;
ResultSet res = null; ResultSet res = null;
try { try {
@ -1653,10 +1656,10 @@ public abstract class JobsDAO {
PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(res.getInt(JobsTableFields.userid.getCollumn())); PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(res.getInt(JobsTableFields.userid.getCollumn()));
if (info == null) if (info == null)
continue; continue;
if (info.getName() == null)
continue;
TopList top = new TopList(info, res.getInt("totallvl"), 0); TopList top = new TopList(info, res.getInt("totallvl"), 0);
names.add(top); names.add(top);
if (names.size() >= Jobs.getGCManager().JobsTopAmount) if (names.size() >= Jobs.getGCManager().JobsTopAmount)
break; break;
} }
@ -1666,6 +1669,7 @@ public abstract class JobsDAO {
close(res); close(res);
close(prest); close(prest);
} }
return names; return names;
} }
@ -1681,6 +1685,10 @@ public abstract class JobsDAO {
if (conn == null) if (conn == null)
return names; return names;
if (start < 0) {
start = 0;
}
PreparedStatement prest = null; PreparedStatement prest = null;
ResultSet res = null; ResultSet res = null;
try { try {

View File

@ -297,9 +297,6 @@ public class JobsPaymentListener implements Listener {
if (block == null || !Jobs.getGCManager().canPerformActionInWorld(block.getWorld())) if (block == null || !Jobs.getGCManager().canPerformActionInWorld(block.getWorld()))
return; return;
if (!Jobs.getGCManager().isBrewingStandsReassign())
return;
if (!block.hasMetadata(brewingOwnerMetadata)) if (!block.hasMetadata(brewingOwnerMetadata))
return; return;
@ -1004,9 +1001,6 @@ public class JobsPaymentListener implements Listener {
if (block == null || !Jobs.getGCManager().canPerformActionInWorld(block.getWorld())) if (block == null || !Jobs.getGCManager().canPerformActionInWorld(block.getWorld()))
return; return;
if (!Jobs.getGCManager().isFurnacesReassign())
return;
if (!block.hasMetadata(furnaceOwnerMetadata)) if (!block.hasMetadata(furnaceOwnerMetadata))
return; return;
@ -1593,10 +1587,6 @@ public class JobsPaymentListener implements Listener {
return; return;
Player p = event.getPlayer(); Player p = event.getPlayer();
if (p == null) {
return;
}
if (!Jobs.getGCManager().canPerformActionInWorld(p.getWorld())) if (!Jobs.getGCManager().canPerformActionInWorld(p.getWorld()))
return; return;
@ -1641,17 +1631,17 @@ public class JobsPaymentListener implements Listener {
} }
} }
if (cmat.equals(CMIMaterial.FURNACE) || cmat.equals(CMIMaterial.LEGACY_BURNING_FURNACE) || cmat.equals(CMIMaterial.SMOKER) || cmat.equals(CMIMaterial.BLAST_FURNACE)) { if (cmat.equals(CMIMaterial.FURNACE) || cmat.equals(CMIMaterial.LEGACY_BURNING_FURNACE)
if (!Jobs.getGCManager().isFurnacesReassign()) || cmat.equals(CMIMaterial.SMOKER) || cmat.equals(CMIMaterial.BLAST_FURNACE)) {
return;
ownershipFeedback done = FurnaceBrewingHandling.registerFurnaces(p, block); ownershipFeedback done = FurnaceBrewingHandling.registerFurnaces(p, block);
if (done.equals(ownershipFeedback.tooMany)) { if (done.equals(ownershipFeedback.tooMany)) {
boolean report = false; boolean report = false;
if (block.hasMetadata(furnaceOwnerMetadata)) { if (block.hasMetadata(furnaceOwnerMetadata)) {
List<MetadataValue> data = block.getMetadata(furnaceOwnerMetadata); List<MetadataValue> data = block.getMetadata(furnaceOwnerMetadata);
if (data.isEmpty()) if (data.isEmpty())
return; return;
// only care about first // only care about first
MetadataValue value = data.get(0); MetadataValue value = data.get(0);
String uuid = value.asString(); String uuid = value.asString();
@ -1669,16 +1659,15 @@ public class JobsPaymentListener implements Listener {
"[max]", jPlayer.getMaxFurnacesAllowed() == 0 ? "-" : jPlayer.getMaxFurnacesAllowed())); "[max]", jPlayer.getMaxFurnacesAllowed() == 0 ? "-" : jPlayer.getMaxFurnacesAllowed()));
} }
} else if (cmat.equals(CMIMaterial.BREWING_STAND) || cmat.equals(CMIMaterial.LEGACY_BREWING_STAND)) { } else if (cmat.equals(CMIMaterial.BREWING_STAND) || cmat.equals(CMIMaterial.LEGACY_BREWING_STAND)) {
if (!Jobs.getGCManager().isBrewingStandsReassign())
return;
ownershipFeedback done = FurnaceBrewingHandling.registerBrewingStand(p, block); ownershipFeedback done = FurnaceBrewingHandling.registerBrewingStand(p, block);
if (done.equals(ownershipFeedback.tooMany)) { if (done.equals(ownershipFeedback.tooMany)) {
boolean report = false; boolean report = false;
if (block.hasMetadata(brewingOwnerMetadata)) { if (block.hasMetadata(brewingOwnerMetadata)) {
List<MetadataValue> data = block.getMetadata(brewingOwnerMetadata); List<MetadataValue> data = block.getMetadata(brewingOwnerMetadata);
if (data.isEmpty()) if (data.isEmpty())
return; return;
// only care about first // only care about first
MetadataValue value = data.get(0); MetadataValue value = data.get(0);
String uuid = value.asString(); String uuid = value.asString();
@ -1717,7 +1706,6 @@ public class JobsPaymentListener implements Listener {
Block b = loc.getBlock(); Block b = loc.getBlock();
if (b.getType().toString().startsWith("STRIPPED_") && jPlayer != null) if (b.getType().toString().startsWith("STRIPPED_") && jPlayer != null)
Jobs.action(jPlayer, new BlockActionInfo(b, ActionType.STRIPLOGS), b); Jobs.action(jPlayer, new BlockActionInfo(b, ActionType.STRIPLOGS), b);
return;
} }
}, 1); }, 1);
} }

View File

@ -247,9 +247,7 @@ public class FurnaceBrewingHandling {
return ownershipFeedback.invalid; return ownershipFeedback.invalid;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
int max = jPlayer.getMaxFurnacesAllowed(); int max = jPlayer.getMaxFurnacesAllowed();
int have = jPlayer.getFurnaceCount(); int have = jPlayer.getFurnaceCount();
boolean owner = false; boolean owner = false;
@ -277,24 +275,25 @@ public class FurnaceBrewingHandling {
block.setMetadata(JobsPaymentListener.furnaceOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), player.getUniqueId().toString())); block.setMetadata(JobsPaymentListener.furnaceOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), player.getUniqueId().toString()));
if (!Jobs.getGCManager().isFurnacesReassign()) {
return ownershipFeedback.newReg;
}
List<blockLoc> ls = furnaceMap.get(player.getUniqueId()); List<blockLoc> ls = furnaceMap.get(player.getUniqueId());
if (ls == null) if (ls == null)
ls = new ArrayList<blockLoc>(); ls = new ArrayList<blockLoc>();
ls.add(new blockLoc(block.getLocation())); ls.add(new blockLoc(block.getLocation()));
furnaceMap.put(player.getUniqueId(), ls); furnaceMap.put(player.getUniqueId(), ls);
return ownershipFeedback.newReg; return ownershipFeedback.newReg;
} }
public static ownershipFeedback registerBrewingStand(Player player, Block block) { public static ownershipFeedback registerBrewingStand(Player player, Block block) {
if (!CMIMaterial.get(block).equals(CMIMaterial.BREWING_STAND) && !CMIMaterial.get(block).equals(CMIMaterial.LEGACY_BREWING_STAND)) if (!CMIMaterial.get(block).equals(CMIMaterial.BREWING_STAND) && !CMIMaterial.get(block).equals(CMIMaterial.LEGACY_BREWING_STAND))
return ownershipFeedback.invalid; return ownershipFeedback.invalid;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
int max = jPlayer.getMaxBrewingStandsAllowed(); int max = jPlayer.getMaxBrewingStandsAllowed();
int have = jPlayer.getBrewingStandCount(); int have = jPlayer.getBrewingStandCount();
boolean owner = false; boolean owner = false;
@ -313,6 +312,7 @@ public class FurnaceBrewingHandling {
return ownershipFeedback.notOwn; return ownershipFeedback.notOwn;
} }
} }
if (owner) if (owner)
return ownershipFeedback.old; return ownershipFeedback.old;
@ -321,12 +321,16 @@ public class FurnaceBrewingHandling {
block.setMetadata(JobsPaymentListener.brewingOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), player.getUniqueId().toString())); block.setMetadata(JobsPaymentListener.brewingOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), player.getUniqueId().toString()));
if (!Jobs.getGCManager().isBrewingStandsReassign()) {
return ownershipFeedback.newReg;
}
List<blockLoc> ls = brewingMap.get(player.getUniqueId()); List<blockLoc> ls = brewingMap.get(player.getUniqueId());
if (ls == null) if (ls == null)
ls = new ArrayList<blockLoc>(); ls = new ArrayList<blockLoc>();
ls.add(new blockLoc(block.getLocation())); ls.add(new blockLoc(block.getLocation()));
brewingMap.put(player.getUniqueId(), ls); brewingMap.put(player.getUniqueId(), ls);
return ownershipFeedback.newReg; return ownershipFeedback.newReg;
} }
@ -334,15 +338,19 @@ public class FurnaceBrewingHandling {
List<blockLoc> ls = furnaceMap.remove(uuid); List<blockLoc> ls = furnaceMap.remove(uuid);
if (ls == null) if (ls == null)
return 0; return 0;
for (blockLoc one : ls) { for (blockLoc one : ls) {
Block block = one.getBlock(); Block block = one.getBlock();
if (block == null) if (block == null)
continue; continue;
CMIMaterial cmat = CMIMaterial.get(block); CMIMaterial cmat = CMIMaterial.get(block);
if (!cmat.equals(CMIMaterial.FURNACE) && !cmat.equals(CMIMaterial.LEGACY_BURNING_FURNACE) && !cmat.equals(CMIMaterial.SMOKER) && !cmat.equals(CMIMaterial.BLAST_FURNACE)) if (!cmat.equals(CMIMaterial.FURNACE) && !cmat.equals(CMIMaterial.LEGACY_BURNING_FURNACE) && !cmat.equals(CMIMaterial.SMOKER) && !cmat.equals(CMIMaterial.BLAST_FURNACE))
continue; continue;
block.removeMetadata(JobsPaymentListener.furnaceOwnerMetadata, Jobs.getInstance()); block.removeMetadata(JobsPaymentListener.furnaceOwnerMetadata, Jobs.getInstance());
} }
return ls.size(); return ls.size();
} }