added RecoveryCompass #7
@@ -0,0 +1,32 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.recoveryCompass;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
class KeepRecoveryCompassOnDeathListener extends ApplianceListener<RecoveryCompass> {
|
||||||
|
@EventHandler
|
||||||
|
public void onDeath(PlayerDeathEvent event) {
|
||||||
|
ItemStack source = event.getDrops().stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(item -> item.getType() == Material.RECOVERY_COMPASS)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (source == null) return;
|
||||||
|
|
||||||
|
if (source.getAmount() > 1) {
|
||||||
|
source.setAmount(source.getAmount() - 1);
|
||||||
|
} else {
|
||||||
|
event.getDrops().remove(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack kept = source.clone();
|
||||||
|
kept.setAmount(1);
|
||||||
|
event.getItemsToKeep().add(kept);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,24 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.recoveryCompass;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
class PlayerFirstJoinCompassGift extends ApplianceListener<RecoveryCompass> {
|
||||||
|
private final NamespacedKey alreadyGiftedKey = new NamespacedKey(this.getClass().getSimpleName().toLowerCase(), "alreadyGifted".toLowerCase());
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
PersistentDataContainer container = player.getPersistentDataContainer();
|
||||||
|
if(container.has(alreadyGiftedKey)) return;
|
||||||
|
player.getInventory().addItem(ItemStack.of(Material.RECOVERY_COMPASS));
|
||||||
|
container.set(alreadyGiftedKey, PersistentDataType.BOOLEAN, true);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.recoveryCompass;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RecoveryCompass extends Appliance {
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(
|
||||||
MineTec marked this conversation as resolved
|
|||||||
|
new PlayerFirstJoinCompassGift(),
|
||||||
|
new KeepRecoveryCompassOnDeathListener()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -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
logging entfernen