"Various" fixes

master
Alexander B 4 years ago
parent a74b74addd
commit dbdcd10a40

@ -12,6 +12,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import java.io.IOException;
public class OnBlockBreak implements Listener { public class OnBlockBreak implements Listener {
@ -21,46 +24,77 @@ public class OnBlockBreak implements Listener {
Player p = e.getPlayer(); Player p = e.getPlayer();
if(e.getBlock().getType() == Material.MOB_SPAWNER){ if(e.getBlock().getType() == Material.MOB_SPAWNER){
// Allow creative Location loc = e.getBlock().getLocation();
if(p.getGameMode() == GameMode.CREATIVE) String locSer = Main.serialiseLocation(loc);
return;
// Get spawner-source (unknown, player, admin) // Get spawner-source (unknown, player, admin)
Location loc = e.getBlock().getLocation();
BlockSource bSource; BlockSource bSource;
Boolean placedByAdmin = Main.data.getBoolean(Main.serialiseLocation(loc)); Object placedByAdmin = Main.data.get(locSer);
if(placedByAdmin == null) if(placedByAdmin == null)
bSource = BlockSource.UNKNOWN; bSource = BlockSource.UNKNOWN;
else else
if(!placedByAdmin) if(!(boolean)placedByAdmin)
bSource = BlockSource.PLAYER; bSource = BlockSource.PLAYER;
else else
bSource = BlockSource.ADMIN; bSource = BlockSource.ADMIN;
// Ignore creative
if(p.getGameMode() != GameMode.CREATIVE){
// # Break-Prerequisite // # Break-Prerequisite
ConfigurationSection breakPreConfig = Main.config.getConfigurationSection("break.break-prerequisite."+ bSource); ConfigurationSection breakPreConfig = Main.config.getConfigurationSection("break.break-prerequisite."+ bSource);
boolean success = false;
// Silktouch // Silktouch
if(breakPreConfig.getBoolean("silktouch")){ if(breakPreConfig.getBoolean("silktouch")){
if(!p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
success = true;
else
e.setCancelled(true); e.setCancelled(true);
} }
// Send msg // Send msg
String msg = breakPreConfig.getString("msg."+ (e.isCancelled()?"fail":"success")); String msg = breakPreConfig.getString("msg."+ (success?"success":"fail"));
if(msg != null && !msg.equals("")) p.sendMessage(msg); if(msg != null && !msg.equals("")) p.sendMessage(msg);
// Stop if breaking wasnt successful
if(!success) return;
}
if(e.isCancelled()) return; // Remove block from data
if(bSource != BlockSource.UNKNOWN){
Main.data.set(locSer, null);
try {
Main.data.save("data.yml");
} catch (IOException ex) {
Main.plugin.getLogger().severe("Cannot save data to data.yml! Data will lost after restart!");
ex.printStackTrace();
}
}
// Ignore creative
if(p.getGameMode() != GameMode.CREATIVE){
// # Drop-Prerequisite // # Drop-Prerequisite
ConfigurationSection dropPreConfig = Main.config.getConfigurationSection("break.drop-prerequisite."+ bSource); ConfigurationSection dropPreConfig = Main.config.getConfigurationSection("break.drop-prerequisite."+ bSource);
boolean success = false;
// Silktouch // Silktouch
if(breakPreConfig.getBoolean("silktouch")){ if(dropPreConfig.getBoolean("silktouch")){
if(!p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) if(p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
e.setDropItems(false); success = true;
else
e.setCancelled(true);
} }
// Set drop
if(success){
ItemStack item = new ItemStack(Material.MOB_SPAWNER);
loc.getWorld().dropItem(loc, item);
}
// Send msg // Send msg
msg = dropPreConfig.getString("msg."+ (e.isDropItems()?"success":"fail")); String msg = dropPreConfig.getString("msg."+ (success?"success":"fail"));
if(msg != null && !msg.equals("")) p.sendMessage(msg); if(msg != null && !msg.equals("")) p.sendMessage(msg);
} }
} }
} }
}

@ -4,6 +4,7 @@ import eu.railduction.ruakij.spawnerDrops.Main;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
@ -11,6 +12,7 @@ import java.io.IOException;
public class OnBlockPlace implements Listener { public class OnBlockPlace implements Listener {
@EventHandler
public void onBlockPlaceEvent(BlockPlaceEvent e){ public void onBlockPlaceEvent(BlockPlaceEvent e){
Player p = e.getPlayer(); Player p = e.getPlayer();
@ -20,18 +22,22 @@ public class OnBlockPlace implements Listener {
// Can break? // Can break?
boolean isAdmin = p.hasPermission("spawnerDrops.admin"); boolean isAdmin = p.hasPermission("spawnerDrops.admin");
if(!isAdmin && !Main.config.getBoolean("place.player.canPlace")){ if(!isAdmin && !Main.config.getBoolean("place.PLAYER.canPlace")){
// Cancel place-event // Cancel place-event
e.setCancelled(true); e.setCancelled(true);
// Send msg // Send msg
String msg = Main.config.getString("place.player.msg.fail"); String msg = Main.config.getString("place.PLAYER.msg.fail");
if(msg != null && !msg.equals("")) p.sendMessage(msg); if(msg != null && !msg.equals("")) p.sendMessage(msg);
return;
} }
else{
// Write place-data // Write place-data
Main.plugin.getLogger().info(Main.serialiseLocation(loc) +" - "+ isAdmin);
Main.data.set(Main.serialiseLocation(loc), isAdmin); Main.data.set(Main.serialiseLocation(loc), isAdmin);
try { try {
Main.data.save("data.yml"); Main.data.save("data.yml");
} catch (IOException ex) { } catch (IOException ex) {
@ -40,9 +46,8 @@ public class OnBlockPlace implements Listener {
} }
// Send msg // Send msg
String msg = Main.config.getString("place.player.msg.success"); String msg = Main.config.getString("place."+ (isAdmin?"ADMIN":"PLAYER") +".msg.success");
if(msg != null && !msg.equals("")) p.sendMessage(msg); if(msg != null && !msg.equals("")) p.sendMessage(msg);
} }
} }
} }
}

Loading…
Cancel
Save