forked from Upstream/mmocore
The block tag that prevents blocks from giving out XP now gets properly removed when a block is removed or when a block forms naturally in place of a placed block
(Exploits COULD be present, please report anything you find out in tickets)
This commit is contained in:
parent
0dcc8968c8
commit
c299978e10
@ -34,8 +34,7 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
|
||||
@Override
|
||||
public ExperienceManager<MineBlockExperienceSource> newManager() {
|
||||
return new ExperienceManager<MineBlockExperienceSource>() {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void a(BlockBreakEvent event) {
|
||||
if (event.getPlayer().getGameMode() != GameMode.SURVIVAL)
|
||||
return;
|
||||
|
@ -146,10 +146,19 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This is handled in a separate event because it
|
||||
* needs to happen AFTER it's already checked the tag
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void unregisterPlayerPlacedBlocksTag(BlockBreakEvent event) {
|
||||
if(event.getBlock().hasMetadata("player_placed"))
|
||||
event.getBlock().removeMetadata("player_placed", MMOCore.plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void registerPlayerPlacedBlocksTag(BlockPlaceEvent event) {
|
||||
event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -186,19 +195,15 @@ public class BlockListener implements Listener {
|
||||
* exp is not gained by these blocks
|
||||
*/
|
||||
|
||||
private boolean protect;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void cobblestoneGeneratorHandling(BlockFormEvent event) {
|
||||
if(MMOCore.plugin.getConfig().contains("should-cobblestone-generators-give-exp")) {
|
||||
this.protect = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp");
|
||||
} else{ this.protect = false; }
|
||||
if(event.getBlock().hasMetadata("player_placed"))
|
||||
event.getBlock().removeMetadata("player_placed", MMOCore.plugin);
|
||||
if(MMOCore.plugin.configManager.cobbleGeneratorXP) return;
|
||||
|
||||
if(!protect) {
|
||||
if (event.getBlock().getType() == Material.WATER || event.getBlock().getType() == Material.LAVA)
|
||||
if (event.getNewState().getType() == Material.COBBLESTONE || event.getNewState().getType() == Material.OBSIDIAN)
|
||||
event.getNewState().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
|
||||
}
|
||||
if (event.getBlock().getType() == Material.WATER || event.getBlock().getType() == Material.LAVA)
|
||||
if (event.getNewState().getType() == Material.COBBLESTONE || event.getNewState().getType() == Material.OBSIDIAN)
|
||||
event.getNewState().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
|
@ -24,7 +24,7 @@ import java.util.logging.Level;
|
||||
public class ConfigManager {
|
||||
public final CommandVerbose commandVerbose = new CommandVerbose();
|
||||
|
||||
public boolean overrideVanillaExp, canCreativeCast;
|
||||
public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP;
|
||||
public double expPartyBuff, regenPartyBuff;
|
||||
public String partyChatPrefix, noSkillBoundPlaceholder;
|
||||
public ChatColor staminaFull, staminaHalf, staminaEmpty;
|
||||
@ -94,22 +94,19 @@ public class ConfigManager {
|
||||
messages = new ConfigFile("messages").getConfig();
|
||||
chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input");
|
||||
partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix");
|
||||
combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000;
|
||||
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000;
|
||||
lootChestPlayerCooldown = MMOCore.plugin.getConfig().getInt("player-cooldown") * 1000;
|
||||
combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000L;
|
||||
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000L;
|
||||
lootChestPlayerCooldown = MMOCore.plugin.getConfig().getInt("player-cooldown") * 1000L;
|
||||
noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message();
|
||||
|
||||
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
|
||||
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);
|
||||
staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE);
|
||||
|
||||
normalSwapAction = EnumUtils.getIfPresent(SwapAction.class,
|
||||
MMOCore.plugin.getConfig().getString("swap-keybind.normal")
|
||||
.toUpperCase()).orElse(SwapAction.VANILLA);
|
||||
sneakingSwapAction = EnumUtils.getIfPresent(SwapAction.class,
|
||||
MMOCore.plugin.getConfig().getString("swap-keybind.sneaking")
|
||||
.toUpperCase()).orElse(SwapAction.VANILLA);
|
||||
normalSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.normal").toUpperCase()).orElse(SwapAction.VANILLA);
|
||||
sneakingSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.sneaking").toUpperCase()).orElse(SwapAction.VANILLA);
|
||||
canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast");
|
||||
cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp");
|
||||
}
|
||||
|
||||
private ChatColor getColorOrDefault(String key, ChatColor defaultColor) {
|
||||
@ -132,16 +129,14 @@ public class ConfigManager {
|
||||
public void loadDefaultFile(String path, String name) {
|
||||
String newPath = path.isEmpty() ? "" : "/" + path;
|
||||
File folder = new File(MMOCore.plugin.getDataFolder() + (newPath));
|
||||
if (!folder.exists())
|
||||
folder.mkdir();
|
||||
if (!folder.exists()) folder.mkdir();
|
||||
|
||||
File file = new File(MMOCore.plugin.getDataFolder() + (newPath), name);
|
||||
if (!file.exists())
|
||||
try {
|
||||
Files.copy(MMOCore.plugin.getResource("default/" + (path.isEmpty() ? "" : path + "/") + name), file.getAbsoluteFile().toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!file.exists()) try {
|
||||
Files.copy(MMOCore.plugin.getResource("default/" + (path.isEmpty() ? "" : path + "/") + name), file.getAbsoluteFile().toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getMessage(String key) {
|
||||
@ -174,10 +169,8 @@ public class ConfigManager {
|
||||
String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message;
|
||||
|
||||
if (!msg.isEmpty()) {
|
||||
if (actionbar)
|
||||
PlayerData.get(player.getUniqueId()).displayActionBar(msg);
|
||||
else
|
||||
player.sendMessage(msg);
|
||||
if (actionbar) PlayerData.get(player.getUniqueId()).displayActionBar(msg);
|
||||
else player.sendMessage(msg);
|
||||
}
|
||||
return !msg.isEmpty();
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ custom-mine-conditions:
|
||||
# broken when custom mining conditions are met
|
||||
protect-custom-mine: false
|
||||
|
||||
# Whether blocks generated with a "cobblegenerator" should
|
||||
# provide the player with experience points or not
|
||||
should-cobblestone-generators-give-exp: false
|
||||
|
||||
loot-chests:
|
||||
|
Loading…
Reference in New Issue
Block a user