1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +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)
return;
for (JobProgression oneJob : player.getJobProgression()) {
for (JobProgression oneJob : player.progression) {
if (oneJob.getLastExperience() != 0) {
ShowJobProgression(player, oneJob, oneJob.getLastExperience());
}

View File

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

View File

@ -63,16 +63,15 @@ public class ScheduleManager {
int from = one.getFrom();
int until = one.getUntil();
List<String> days = one.getDays();
if (one.isStarted() && one.getBroadcastInfoOn() < System.currentTimeMillis() && one.getBroadcastInterval() > 0) {
one.setBroadcastInfoOn(System.currentTimeMillis() + one.getBroadcastInterval() * 60 * 1000);
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
.isStarted()) || !one.isNextDay() && (current >= from && current < until)) && (days.contains(currentDayName) || days.contains("all")) && !one
.isStarted()) {
.isStarted()) || !one.isNextDay() && (current >= from && current < until)) && containsDays && !one.isStarted()) {
JobsScheduleStartEvent event = new JobsScheduleStartEvent(one);
Bukkit.getPluginManager().callEvent(event);
@ -95,8 +94,8 @@ public class ScheduleManager {
one.setStarted(true);
one.setStoped(false);
break;
} else if (((one.isNextDay() && current > one.getNextUntil() && current < one.getFrom() && !one.isStoped()) || !one.isNextDay() && current > until
&& ((days.contains(currentDayName)) || days.contains("all"))) && !one.isStoped()) {
} else if (((one.isNextDay() && current > one.getNextUntil() && current < one.getFrom() && !one.isStoped()) || (!one.isNextDay() && current > until
&& containsDays)) && !one.isStoped()) {
JobsScheduleStopEvent event = new JobsScheduleStopEvent(one);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
@ -194,11 +193,11 @@ public class ScheduleManager {
sched.setMessageToBroadcast(path.getStringList("BroadcastMessage"), path.getString("From"), path.getString("Until"));
if (path.isDouble("Exp"))
sched.setBoost(CurrencyType.EXP, path.getDouble("Exp", 0D));
sched.setBoost(CurrencyType.EXP, path.getDouble("Exp"));
if (path.isDouble("Money"))
sched.setBoost(CurrencyType.MONEY, path.getDouble("Money", 0D));
sched.setBoost(CurrencyType.MONEY, path.getDouble("Money"));
if (path.isDouble("Points"))
sched.setBoost(CurrencyType.POINTS, path.getDouble("Points", 0D));
sched.setBoost(CurrencyType.POINTS, path.getDouble("Points"));
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) {
if (isTable(table.getTableName()))
return true;
@ -2623,12 +2600,8 @@ public abstract class JobsDAO {
return;
}
Statement stmt = null;
try {
stmt = conn.createStatement();
try (Statement stmt = conn.createStatement()) {
stmt.execute(sql);
} finally {
close(stmt);
}
}

View File

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

View File

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

View File

@ -24,9 +24,9 @@ public final class JobsPayment14Listener implements Listener {
// BlockCookEvent does not have "cooking owner"
private final Map<UUID, List<PlayerCamp>> campPlayers = new HashMap<>();
@EventHandler(priority = EventPriority.LOW)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onCook(BlockCookEvent event) {
if (event.isCancelled() || !(event.getBlock().getType() != Material.CAMPFIRE) || campPlayers.isEmpty())
if (!(event.getBlock().getType() != Material.CAMPFIRE) || campPlayers.isEmpty())
return;
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) {
if (event.getBlock().getType() != Material.CAMPFIRE || campPlayers.isEmpty())
return;
@ -95,7 +95,7 @@ public final class JobsPayment14Listener implements Listener {
if (click == null || click.getType() != Material.CAMPFIRE || !ev.hasItem())
return;
if (!Jobs.getGCManager().canPerformActionInWorld(click.getWorld()) || !JobsPaymentListener.payIfCreative(ev.getPlayer()))
if (!JobsPaymentListener.payIfCreative(ev.getPlayer()) || !Jobs.getGCManager().canPerformActionInWorld(click.getWorld()))
return;
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)
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
switch (event.getAction()) {
case NOTHING:
@ -137,6 +131,9 @@ public class JobsPaymentListener implements Listener {
break;
}
if (!Jobs.getGCManager().canPerformActionInWorld(event.getWhoClicked().getWorld()))
return;
if (event.getInventory().getType() != InventoryType.MERCHANT || event.getSlot() != 2 || event.getSlotType() != SlotType.RESULT)
return;
@ -915,9 +912,6 @@ public class JobsPaymentListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEnchantItem(EnchantItemEvent event) {
if (event.isCancelled())
return;
if (!Jobs.getGCManager().canPerformActionInWorld(event.getEnchanter().getWorld()))
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) {
if (event.isCancelled())
return;
Player p = event.getPlayer();
if (!Jobs.getGCManager().canPerformActionInWorld(p.getWorld()))
return;
@ -1643,9 +1634,9 @@ public class JobsPaymentListener implements Listener {
}
}
@EventHandler
@EventHandler(ignoreCancelled = true)
public void onExplore(JobsChunkChangeEvent event) {
if (event.isCancelled() || !Jobs.getExplore().isExploreEnabled())
if (!Jobs.getExplore().isExploreEnabled())
return;
Player player = event.getPlayer();

View File

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