Compare commits
4 Commits
4068eae5bb
...
master
Author | SHA1 | Date | |
---|---|---|---|
d38871eac9 | |||
238df2feff | |||
e752d7f73b | |||
b0df982be3 |
@@ -1,4 +1,4 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiAutoTotem;
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiAutoTotem;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
@@ -1,4 +1,4 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiAutoTotem;
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiAutoTotem;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.entity.Player;
|
@@ -14,6 +14,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
public class AntiSignEdit extends Appliance {
|
||||
private final Component disallowMessage = Component.text(
|
||||
"Nutze /settings um das Bearbeiten von Schildern zu aktivieren!",
|
||||
NamedTextColor.RED
|
||||
);
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Settings.instance().declareSetting(SignEditSetting.class);
|
||||
@@ -22,8 +27,9 @@ public class AntiSignEdit extends Appliance {
|
||||
public boolean preventSignEdit(Player p, SignSide sign) {
|
||||
SelectSetting.Options.Option setting = Settings.instance().getSetting(p, Settings.Key.SignEdit, SelectSetting.Options.Option.class);
|
||||
if(setting.is(SignEditSetting.editable)) return false;
|
||||
|
||||
if(setting.is(SignEditSetting.readOnly)) {
|
||||
p.sendActionBar(Component.text("Das Bearbeiten von Schildern ist in deinen Einstellungen deaktiviert.", NamedTextColor.RED));
|
||||
p.sendActionBar(this.disallowMessage);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,7 +38,7 @@ public class AntiSignEdit extends Appliance {
|
||||
.anyMatch(line -> !PlainTextComponentSerializer.plainText().serialize(line).isBlank());
|
||||
|
||||
if(hasText) {
|
||||
p.sendActionBar(Component.text("Das Bearbeiten von Schildern, welch bereits beschrieben sind, ist bei dir deaktiviert.", NamedTextColor.RED));
|
||||
p.sendActionBar(this.disallowMessage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.armadilloInfectionReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ArmadilloInfectionReducer extends Appliance {
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new InfectionSpawnListener()
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.armadilloInfectionReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
class InfectionSpawnListener extends ApplianceListener<ArmadilloInfectionReducer> {
|
||||
@EventHandler
|
||||
public void onSpawn(CreatureSpawnEvent event) {
|
||||
if(!event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.POTION_EFFECT)) return;
|
||||
if(!event.getEntity().getType().equals(EntityType.SILVERFISH)) return;
|
||||
if(ThreadLocalRandom.current().nextDouble() > 0.7) event.setCancelled(true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.mendingReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MendingReducer extends Appliance {
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new MendingRepairListener()
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.mendingReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemMendEvent;
|
||||
|
||||
public class MendingRepairListener extends ApplianceListener<MendingReducer> {
|
||||
private static final double COST_MULTIPLIER = 2.0;
|
||||
|
||||
@EventHandler
|
||||
public void onMendingRepair(PlayerItemMendEvent event) {
|
||||
int baseConsumed = event.getConsumedExperience();
|
||||
int orbExp = event.getExperienceOrb().getExperience();
|
||||
|
||||
int desiredTotal = (int) Math.ceil(baseConsumed * COST_MULTIPLIER);
|
||||
int extraCost = Math.max(0, desiredTotal - baseConsumed);
|
||||
|
||||
int maxExtraPossible = Math.max(0, orbExp - baseConsumed);
|
||||
int extraApplied = Math.min(extraCost, maxExtraPossible);
|
||||
|
||||
if (extraApplied > 0) event.getExperienceOrb().setExperience(orbExp - extraApplied);
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.silverfishExpReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
class SilverfishDeathListener extends ApplianceListener<SilverfishExpReducer> {
|
||||
@EventHandler
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
if(!event.getEntity().getType().equals(EntityType.SILVERFISH)) return;
|
||||
event.setDroppedExp(event.getDroppedExp() / 3);
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.silverfishExpReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SilverfishExpReducer extends Appliance {
|
||||
@Override
|
||||
public @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new SilverfishDeathListener()
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.tooling.antiGrief;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.appliances.tooling.antiGrief.player.PlayerGriefListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.BlockDisplay;
|
||||
import org.bukkit.entity.ItemDisplay;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Transformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AntiGrief extends Appliance {
|
||||
private final Map<Block, UUID> blockRegistry = new HashMap<>();
|
||||
|
||||
public void addTracking(Block block, UUID player) {
|
||||
this.blockRegistry.put(block, player);
|
||||
block.getLocation().getWorld().spawn(block.getLocation(), ItemDisplay.class, itemDisplay -> {
|
||||
itemDisplay.setItemStack(ItemStack.of(Material.FIRE_CHARGE));
|
||||
itemDisplay.teleport(block.getLocation().add(0.5, 0.5, 0.5));
|
||||
});
|
||||
}
|
||||
|
||||
public @Nullable UUID getTracked(Block block) {
|
||||
return this.blockRegistry.get(block);
|
||||
}
|
||||
|
||||
public void addDestroyed(Block block, UUID player) {
|
||||
block.getLocation().getWorld().spawn(block.getLocation().add(0.5, 0.5, 0.5), BlockDisplay.class, blockDisplay -> {
|
||||
blockDisplay.setBlock(Material.GOLD_BLOCK.createBlockData());
|
||||
|
||||
Transformation transformation = blockDisplay.getTransformation();
|
||||
transformation.getScale().set(0.3);
|
||||
blockDisplay.setTransformation(transformation);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(new PlayerGriefListener());
|
||||
}
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.tooling.antiGrief.player;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.appliances.tooling.antiGrief.AntiGrief;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerGriefListener extends ApplianceListener<AntiGrief> {
|
||||
@EventHandler
|
||||
public void onIgnite(BlockIgniteEvent event) {
|
||||
Bukkit.broadcast(Component.text(event.getCause().toString()));
|
||||
switch(event.getCause()) {
|
||||
case LAVA:
|
||||
case SPREAD:
|
||||
case EXPLOSION:
|
||||
if(event.getIgnitingBlock() == null) return;
|
||||
UUID ignitedBy = this.getAppliance().getTracked(event.getIgnitingBlock());
|
||||
this.getAppliance().addTracking(event.getBlock(), ignitedBy);
|
||||
break;
|
||||
|
||||
case FLINT_AND_STEEL:
|
||||
case ENDER_CRYSTAL:
|
||||
case ARROW:
|
||||
case FIREBALL:
|
||||
if(event.getPlayer() == null) return;
|
||||
this.getAppliance().addTracking(event.getBlock(), event.getPlayer().getUniqueId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSpread(BlockSpreadEvent event) {
|
||||
if(!event.getBlock().getType().equals(Material.FIRE)) return;
|
||||
UUID ignitedBy = this.getAppliance().getTracked(event.getBlock());
|
||||
this.getAppliance().addTracking(event.getBlock(), ignitedBy);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDestroy(BlockBurnEvent event) {
|
||||
UUID ignitedBy = this.getAppliance().getTracked(event.getIgnitingBlock());
|
||||
if(ignitedBy == null) return;
|
||||
this.getAppliance().addDestroyed(event.getBlock(), ignitedBy);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user