1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Cancelled event methods with ignoreCancelled annotation value will not be called

This commit is contained in:
montlikadani 2021-05-20 16:17:44 +02:00
parent 5f3b8526c7
commit 96379db923
9 changed files with 50 additions and 87 deletions

View File

@ -28,7 +28,7 @@ public class BossBarManager {
if (Version.getCurrent().isLower(Version.v1_9_R1) || player == null) if (Version.getCurrent().isLower(Version.v1_9_R1) || player == null)
return; return;
for (JobProgression oneJob : player.getJobProgression()) { for (JobProgression oneJob : player.progression) {
if (oneJob.getLastExperience() != 0) { if (oneJob.getLastExperience() != 0) {
ShowJobProgression(player, oneJob, oneJob.getLastExperience()); ShowJobProgression(player, oneJob, oneJob.getLastExperience());
} }

View File

@ -476,7 +476,7 @@ public class ConfigManager {
cfg.save(); cfg.save();
} }
private static void generate(ConfigReader cfg, String pt) { private void generate(ConfigReader cfg, String pt) {
cfg.get(pt + ".income", 1D); cfg.get(pt + ".income", 1D);
cfg.get(pt + ".points", 1D); cfg.get(pt + ".points", 1D);
cfg.get(pt + ".experience", 1D); cfg.get(pt + ".experience", 1D);
@ -554,20 +554,19 @@ public class ConfigManager {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public KeyValues getKeyValue(String myKey, ActionType actionType, String jobName) { public KeyValues getKeyValue(String myKey, ActionType actionType, String jobName) {
String type = null, String subType = "", meta = "";
subType = "",
meta = "";
final String finalMyKey = myKey; final String finalMyKey = myKey;
int id = 0;
if (myKey.contains("-")) { if (myKey.contains("-")) {
// uses subType
String[] split = myKey.split("-", 2); String[] split = myKey.split("-", 2);
if (split.length >= 2) { if (split.length >= 2) {
subType = ":" + split[1]; subType = ":" + split[1];
meta = split[1]; meta = split[1];
myKey = split[0];
} }
myKey = split[0];
} else if (myKey.contains(":")) { // when we uses tipped arrow effect types } else if (myKey.contains(":")) { // when we uses tipped arrow effect types
String[] split = myKey.split(":", 2); String[] split = myKey.split(":", 2);
meta = split.length > 1 ? split[1] : myKey; meta = split.length > 1 ? split[1] : myKey;
@ -575,6 +574,9 @@ public class ConfigManager {
myKey = split[0]; myKey = split[0];
} }
String type = null;
int id = 0;
CMIMaterial material = CMIMaterial.NONE; CMIMaterial material = CMIMaterial.NONE;
switch (actionType) { switch (actionType) {

View File

@ -63,16 +63,15 @@ public class ScheduleManager {
int from = one.getFrom(); int from = one.getFrom();
int until = one.getUntil(); int until = one.getUntil();
List<String> days = one.getDays();
if (one.isStarted() && one.getBroadcastInfoOn() < System.currentTimeMillis() && one.getBroadcastInterval() > 0) { if (one.isStarted() && one.getBroadcastInfoOn() < System.currentTimeMillis() && one.getBroadcastInterval() > 0) {
one.setBroadcastInfoOn(System.currentTimeMillis() + one.getBroadcastInterval() * 60 * 1000); one.setBroadcastInfoOn(System.currentTimeMillis() + one.getBroadcastInterval() * 60 * 1000);
plugin.getComplement().broadcastMessage(one.getMessageToBroadcast()); plugin.getComplement().broadcastMessage(one.getMessageToBroadcast());
} }
boolean containsDays = one.getDays().contains(currentDayName) || one.getDays().contains("all");
if (((one.isNextDay() && (current >= from && current < until || current >= one.getNextFrom() && current < one.getNextUntil()) && !one if (((one.isNextDay() && (current >= from && current < until || current >= one.getNextFrom() && current < one.getNextUntil()) && !one
.isStarted()) || !one.isNextDay() && (current >= from && current < until)) && (days.contains(currentDayName) || days.contains("all")) && !one .isStarted()) || !one.isNextDay() && (current >= from && current < until)) && containsDays && !one.isStarted()) {
.isStarted()) {
JobsScheduleStartEvent event = new JobsScheduleStartEvent(one); JobsScheduleStartEvent event = new JobsScheduleStartEvent(one);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
@ -95,8 +94,8 @@ public class ScheduleManager {
one.setStarted(true); one.setStarted(true);
one.setStoped(false); one.setStoped(false);
break; break;
} else if (((one.isNextDay() && current > one.getNextUntil() && current < one.getFrom() && !one.isStoped()) || !one.isNextDay() && current > until } else if (((one.isNextDay() && current > one.getNextUntil() && current < one.getFrom() && !one.isStoped()) || (!one.isNextDay() && current > until
&& ((days.contains(currentDayName)) || days.contains("all"))) && !one.isStoped()) { && containsDays)) && !one.isStoped()) {
JobsScheduleStopEvent event = new JobsScheduleStopEvent(one); JobsScheduleStopEvent event = new JobsScheduleStopEvent(one);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
@ -194,11 +193,11 @@ public class ScheduleManager {
sched.setMessageToBroadcast(path.getStringList("BroadcastMessage"), path.getString("From"), path.getString("Until")); sched.setMessageToBroadcast(path.getStringList("BroadcastMessage"), path.getString("From"), path.getString("Until"));
if (path.isDouble("Exp")) if (path.isDouble("Exp"))
sched.setBoost(CurrencyType.EXP, path.getDouble("Exp", 0D)); sched.setBoost(CurrencyType.EXP, path.getDouble("Exp"));
if (path.isDouble("Money")) if (path.isDouble("Money"))
sched.setBoost(CurrencyType.MONEY, path.getDouble("Money", 0D)); sched.setBoost(CurrencyType.MONEY, path.getDouble("Money"));
if (path.isDouble("Points")) if (path.isDouble("Points"))
sched.setBoost(CurrencyType.POINTS, path.getDouble("Points", 0D)); sched.setBoost(CurrencyType.POINTS, path.getDouble("Points"));
BOOSTSCHEDULE.add(sched); BOOSTSCHEDULE.add(sched);
} }

View File

@ -516,29 +516,6 @@ public abstract class JobsDAO {
} }
} }
public void setAutoCommit(boolean state) {
JobsConnection conn = getConnection();
if (conn == null)
return;
try {
conn.setAutoCommit(state);
} catch (SQLException e) {
e.printStackTrace();
}
}
public void commit() {
JobsConnection conn = getConnection();
if (conn == null)
return;
try {
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
private boolean createDefaultTable(DBTables table) { private boolean createDefaultTable(DBTables table) {
if (isTable(table.getTableName())) if (isTable(table.getTableName()))
return true; return true;
@ -2623,12 +2600,8 @@ public abstract class JobsDAO {
return; return;
} }
Statement stmt = null; try (Statement stmt = conn.createStatement()) {
try {
stmt = conn.createStatement();
stmt.execute(sql); stmt.execute(sql);
} finally {
close(stmt);
} }
} }

View File

@ -32,6 +32,7 @@ public class JobsManager {
// If it MySQL lets change to SqLite // If it MySQL lets change to SqLite
dbType = DataBaseType.SqLite; dbType = DataBaseType.SqLite;
dao = startSqlite(); dao = startSqlite();
if (dao != null) if (dao != null)
dao.setDbType(dbType); dao.setDbType(dbType);
break; break;
@ -39,6 +40,7 @@ public class JobsManager {
// If it SqLite lets change to MySQL // If it SqLite lets change to MySQL
dbType = DataBaseType.MySQL; dbType = DataBaseType.MySQL;
dao = startMysql(); dao = startMysql();
if (dao != null) if (dao != null)
dao.setDbType(dbType); dao.setDbType(dbType);
break; break;
@ -64,6 +66,7 @@ public class JobsManager {
public void start() { public void start() {
ConfigReader c = Jobs.getGCManager().getConfig(); ConfigReader c = Jobs.getGCManager().getConfig();
c.addComment("storage.method", "storage method, can be MySQL or sqlite"); c.addComment("storage.method", "storage method, can be MySQL or sqlite");
String storageMethod = c.get("storage.method", "sqlite"); String storageMethod = c.get("storage.method", "sqlite");
c.addComment("mysql", "Requires Mysql"); c.addComment("mysql", "Requires Mysql");
@ -82,26 +85,31 @@ public class JobsManager {
if (storageMethod.equalsIgnoreCase("mysql")) { if (storageMethod.equalsIgnoreCase("mysql")) {
dbType = DataBaseType.MySQL; dbType = DataBaseType.MySQL;
dao = startMysql(); dao = startMysql();
} else if (storageMethod.equalsIgnoreCase("sqlite")) {
dbType = DataBaseType.SqLite;
dao = startSqlite();
} else { } else {
Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!"); if (!storageMethod.equalsIgnoreCase("sqlite")) {
c.set("storage.method", "sqlite"); Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!");
c.set("storage.method", "sqlite");
}
dbType = DataBaseType.SqLite; dbType = DataBaseType.SqLite;
dao = startSqlite(); dao = startSqlite();
} }
Jobs.setDAO(dao); Jobs.setDAO(dao);
} }
private synchronized JobsMySQL startMysql() { private synchronized JobsMySQL startMysql() {
ConfigReader c = Jobs.getGCManager().getConfig(); ConfigReader c = Jobs.getGCManager().getConfig();
String legacyUrl = c.getC().getString("mysql.url"); String legacyUrl = c.getC().getString("mysql.url");
if (legacyUrl != null) { if (legacyUrl != null) {
String jdbcString = "jdbc:mysql://"; String jdbcString = "jdbc:mysql://";
if (legacyUrl.toLowerCase().startsWith(jdbcString)) { if (legacyUrl.toLowerCase().startsWith(jdbcString)) {
legacyUrl = legacyUrl.substring(jdbcString.length()); legacyUrl = legacyUrl.substring(jdbcString.length());
String[] parts = legacyUrl.split("/");
String[] parts = legacyUrl.split("/", 2);
if (parts.length >= 2) { if (parts.length >= 2) {
hostname = c.get("mysql.hostname", parts[0]); hostname = c.get("mysql.hostname", parts[0]);
database = c.get("mysql.database", parts[1]); database = c.get("mysql.database", parts[1]);

View File

@ -437,12 +437,9 @@ public class JobsListener implements Listener {
return false; return false;
} }
@EventHandler @EventHandler(ignoreCancelled = true)
public void onChunkChangeMove(PlayerMoveEvent event) { public void onChunkChangeMove(PlayerMoveEvent event) {
if (event.isCancelled() || !event.getPlayer().isOnline()) if (!event.getPlayer().isOnline() || event.getTo() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getTo().getWorld()))
return;
if (event.getTo() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getTo().getWorld()))
return; return;
Chunk from = event.getFrom().getChunk(); Chunk from = event.getFrom().getChunk();
@ -451,12 +448,10 @@ public class JobsListener implements Listener {
plugin.getServer().getPluginManager().callEvent(new JobsChunkChangeEvent(event.getPlayer(), from, to)); plugin.getServer().getPluginManager().callEvent(new JobsChunkChangeEvent(event.getPlayer(), from, to));
} }
@EventHandler @EventHandler(ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) { public void onInventoryClick(InventoryClickEvent event) {
if (event.isCancelled())
return;
boolean shift = false, numberkey = false; boolean shift = false, numberkey = false;
if (event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT) if (event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT)
shift = true; shift = true;
@ -563,11 +558,8 @@ public class JobsListener implements Listener {
} }
} }
@EventHandler @EventHandler(ignoreCancelled = true)
public void dispenserFireEvent(BlockDispenseEvent event) { public void dispenserFireEvent(BlockDispenseEvent event) {
if (event.isCancelled())
return;
ItemStack item = event.getItem(); ItemStack item = event.getItem();
ArmorTypes type = ArmorTypes.matchType(item); ArmorTypes type = ArmorTypes.matchType(item);
if (type == null) if (type == null)

View File

@ -24,9 +24,9 @@ public final class JobsPayment14Listener implements Listener {
// BlockCookEvent does not have "cooking owner" // BlockCookEvent does not have "cooking owner"
private final Map<UUID, List<PlayerCamp>> campPlayers = new HashMap<>(); private final Map<UUID, List<PlayerCamp>> campPlayers = new HashMap<>();
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onCook(BlockCookEvent event) { public void onCook(BlockCookEvent event) {
if (event.isCancelled() || !(event.getBlock().getType() != Material.CAMPFIRE) || campPlayers.isEmpty()) if (!(event.getBlock().getType() != Material.CAMPFIRE) || campPlayers.isEmpty())
return; return;
if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
@ -59,7 +59,7 @@ public final class JobsPayment14Listener implements Listener {
} }
} }
@EventHandler(ignoreCancelled = true) @EventHandler
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (event.getBlock().getType() != Material.CAMPFIRE || campPlayers.isEmpty()) if (event.getBlock().getType() != Material.CAMPFIRE || campPlayers.isEmpty())
return; return;
@ -95,7 +95,7 @@ public final class JobsPayment14Listener implements Listener {
if (click == null || click.getType() != Material.CAMPFIRE || !ev.hasItem()) if (click == null || click.getType() != Material.CAMPFIRE || !ev.hasItem())
return; return;
if (!Jobs.getGCManager().canPerformActionInWorld(click.getWorld()) || !JobsPaymentListener.payIfCreative(ev.getPlayer())) if (!JobsPaymentListener.payIfCreative(ev.getPlayer()) || !Jobs.getGCManager().canPerformActionInWorld(click.getWorld()))
return; return;
List<PlayerCamp> camps = campPlayers.getOrDefault(ev.getPlayer().getUniqueId(), new ArrayList<>()); List<PlayerCamp> camps = campPlayers.getOrDefault(ev.getPlayer().getUniqueId(), new ArrayList<>());

View File

@ -120,12 +120,6 @@ public class JobsPaymentListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void villagerTradeInventoryClick(InventoryClickEvent event) { public void villagerTradeInventoryClick(InventoryClickEvent event) {
if (event.isCancelled())
return;
if (!Jobs.getGCManager().canPerformActionInWorld(event.getWhoClicked().getWorld()))
return;
// If event is nothing or place, do nothing // If event is nothing or place, do nothing
switch (event.getAction()) { switch (event.getAction()) {
case NOTHING: case NOTHING:
@ -137,6 +131,9 @@ public class JobsPaymentListener implements Listener {
break; break;
} }
if (!Jobs.getGCManager().canPerformActionInWorld(event.getWhoClicked().getWorld()))
return;
if (event.getInventory().getType() != InventoryType.MERCHANT || event.getSlot() != 2 || event.getSlotType() != SlotType.RESULT) if (event.getInventory().getType() != InventoryType.MERCHANT || event.getSlot() != 2 || event.getSlotType() != SlotType.RESULT)
return; return;
@ -915,9 +912,6 @@ public class JobsPaymentListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEnchantItem(EnchantItemEvent event) { public void onEnchantItem(EnchantItemEvent event) {
if (event.isCancelled())
return;
if (!Jobs.getGCManager().canPerformActionInWorld(event.getEnchanter().getWorld())) if (!Jobs.getGCManager().canPerformActionInWorld(event.getEnchanter().getWorld()))
return; return;
@ -1548,11 +1542,8 @@ public class JobsPaymentListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.isCancelled())
return;
Player p = event.getPlayer(); Player p = event.getPlayer();
if (!Jobs.getGCManager().canPerformActionInWorld(p.getWorld())) if (!Jobs.getGCManager().canPerformActionInWorld(p.getWorld()))
return; return;
@ -1643,9 +1634,9 @@ public class JobsPaymentListener implements Listener {
} }
} }
@EventHandler @EventHandler(ignoreCancelled = true)
public void onExplore(JobsChunkChangeEvent event) { public void onExplore(JobsChunkChangeEvent event) {
if (event.isCancelled() || !Jobs.getExplore().isExploreEnabled()) if (!Jobs.getExplore().isExploreEnabled())
return; return;
Player player = event.getPlayer(); Player player = event.getPlayer();

View File

@ -17,8 +17,7 @@ public class PistonProtectionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockMove(BlockPistonExtendEvent event) { public void onBlockMove(BlockPistonExtendEvent event) {
if (!Jobs.getGCManager().useBlockProtection || event.isCancelled() if (!Jobs.getGCManager().useBlockProtection || !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
|| !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
return; return;
BlockFace dir = event.getDirection(); BlockFace dir = event.getDirection();
@ -39,8 +38,7 @@ public class PistonProtectionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockRetractMove(BlockPistonRetractEvent event) { public void onBlockRetractMove(BlockPistonRetractEvent event) {
if (!Jobs.getGCManager().useBlockProtection || event.isCancelled() if (!Jobs.getGCManager().useBlockProtection || !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
|| !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
return; return;
BlockFace dir = event.getDirection(); BlockFace dir = event.getDirection();