Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f415b9aba | ||
|
|
aebd7f7bc8 | ||
|
|
410658259d | ||
|
|
1dbc9b29a3 | ||
|
|
b1c92310cb | ||
|
|
15ee6ee79e | ||
|
|
dd2d71d754 | ||
|
|
3221450cde | ||
|
|
f615dc867a | ||
|
|
673bae4d50 | ||
|
|
6ad9407cb4 |
-52
@@ -1,52 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.frostWalkerBoat;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.data.Levelled;
|
|
||||||
import org.bukkit.entity.Boat;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
class BoatMoveListener extends ApplianceListener<FrostWalkerBoat> {
|
|
||||||
@EventHandler
|
|
||||||
public void onBoatMove(VehicleMoveEvent event) {
|
|
||||||
if(!(event.getVehicle() instanceof Boat boat)) return;
|
|
||||||
|
|
||||||
// if(!event.getVehicle().getPersistentDataContainer().has(
|
|
||||||
// this.getAppliance().getNamespacedKey(),
|
|
||||||
// PersistentDataType.BOOLEAN)
|
|
||||||
// ) return;
|
|
||||||
//
|
|
||||||
// if(Boolean.FALSE.equals(event.getVehicle().getPersistentDataContainer().get(
|
|
||||||
// this.getAppliance().getNamespacedKey(),
|
|
||||||
// PersistentDataType.BOOLEAN
|
|
||||||
// ))) return;
|
|
||||||
|
|
||||||
Block blockAtBoat = event.getTo().getBlock();
|
|
||||||
|
|
||||||
if(blockAtBoat.getType() == Material.WATER) {
|
|
||||||
if (!(blockAtBoat.getBlockData() instanceof Levelled waterData)) return;
|
|
||||||
if (waterData.getLevel() != 0) return;
|
|
||||||
if (!blockAtBoat.getRelative(BlockFace.UP).isEmpty()) return;
|
|
||||||
|
|
||||||
Location teleportLocation = event.getTo().clone();
|
|
||||||
teleportLocation.setY(blockAtBoat.getY()+1.1);
|
|
||||||
boat.teleport(teleportLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector velocity = event.getTo().toVector().subtract(event.getFrom().toVector());
|
|
||||||
velocity.setY(0);
|
|
||||||
Block iceTargetBlock;
|
|
||||||
if(velocity.isZero()) {
|
|
||||||
iceTargetBlock = event.getTo().getBlock().getRelative(BlockFace.DOWN);
|
|
||||||
} else {
|
|
||||||
Location iceTargetLocation = blockAtBoat.getLocation().clone().add(velocity.clone().normalize().multiply(5));
|
|
||||||
iceTargetBlock = iceTargetLocation.getBlock().getRelative(BlockFace.DOWN);
|
|
||||||
}
|
|
||||||
this.getAppliance().freezeWater(iceTargetBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.frostWalkerBoat;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.data.Levelled;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FrostWalkerBoat extends Appliance {
|
|
||||||
public NamespacedKey getNamespacedKey() {
|
|
||||||
return new NamespacedKey(this.getClass().getSimpleName().toLowerCase(), "is_frostwalker_enchanted");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void freezeWater(Block targetBlock) {
|
|
||||||
int radius = 4;
|
|
||||||
double circleRadiusSquared = Math.pow(radius + 0.5, 2);
|
|
||||||
|
|
||||||
for(int xOffset = -radius; xOffset <= radius; xOffset++) {
|
|
||||||
for(int zOffset = -radius; zOffset <= radius; zOffset++) {
|
|
||||||
int distanceSquared =
|
|
||||||
xOffset * xOffset + zOffset * zOffset;
|
|
||||||
|
|
||||||
if(distanceSquared > circleRadiusSquared) continue;
|
|
||||||
|
|
||||||
Block block = targetBlock.getRelative(xOffset, 0, zOffset);
|
|
||||||
|
|
||||||
if(block.getType() != Material.WATER) continue;
|
|
||||||
if(!(block.getBlockData() instanceof Levelled waterData)) continue;
|
|
||||||
if(waterData.getLevel() != 0) continue;
|
|
||||||
if(!block.getRelative(BlockFace.UP).isEmpty()) continue;
|
|
||||||
|
|
||||||
block.setType(Material.FROSTED_ICE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
protected List<Listener> listeners() {
|
|
||||||
return List.of(new BoatMoveListener());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.silenceNametag;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.view.AnvilView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NametagAnvilListener extends ApplianceListener<SilenceNametag> {
|
||||||
|
@EventHandler
|
||||||
|
public void onAnvilRename(PrepareAnvilEvent event){
|
||||||
|
ItemStack resultItem = event.getResult();
|
||||||
|
if(resultItem == null) return;
|
||||||
|
|
||||||
|
|
||||||
|
AnvilView anvilView = event.getView();
|
||||||
|
ItemStack inputItem = anvilView.getItem(0);
|
||||||
|
if(inputItem == null || inputItem.getType() != Material.NAME_TAG) return;
|
||||||
|
|
||||||
|
|
||||||
|
if(!SilenceNametag.muteString.equals(anvilView.getRenameText())
|
||||||
|
&& !SilenceNametag.unmuteString.equals(anvilView.getRenameText())) return;
|
||||||
|
|
||||||
|
event.setResult(this.getAppliance().createSilenceNametag(resultItem, anvilView.getRenameText()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.silenceNametag;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class SilenceNametag extends Appliance {
|
||||||
|
public static final String pluginName = "silence-nametag";
|
||||||
|
public static final String muteString = "@verstummen";
|
||||||
|
public static final String unmuteString = "@entstummen";
|
||||||
|
|
||||||
|
public enum NametagActions {
|
||||||
|
SILENCE,
|
||||||
|
UNSILENCE
|
||||||
|
}
|
||||||
|
|
||||||
|
NamespacedKey nametagActionKey =
|
||||||
|
new NamespacedKey(pluginName, "nametag-action");
|
||||||
|
|
||||||
|
ItemStack setNametagAction(ItemStack item, NametagActions action) {
|
||||||
|
Objects.requireNonNull(item, "item must not be null");
|
||||||
|
item.editPersistentDataContainer(pdc -> {
|
||||||
|
pdc.set(
|
||||||
|
nametagActionKey,
|
||||||
|
PersistentDataType.INTEGER,
|
||||||
|
action.ordinal()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
item.editMeta(meta -> {
|
||||||
|
List<Component> lore = meta.hasLore() ? new ArrayList<>(meta.lore()) : new ArrayList<>();
|
||||||
|
if(action == NametagActions.SILENCE) {
|
||||||
|
lore.add(Component.text("Dieses Namensschild verstummt Mobs."));
|
||||||
|
} else if (action == NametagActions.UNSILENCE){
|
||||||
|
lore.add(Component.text("Dieses Namensschild entstummt Mobs."));
|
||||||
|
}
|
||||||
|
meta.customName(null);
|
||||||
|
meta.lore(lore);
|
||||||
|
});
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
NametagActions getNametagAction(ItemStack item) {
|
||||||
|
Objects.requireNonNull(item, "item must not be null");
|
||||||
|
return item.getPersistentDataContainer().get(nametagActionKey, PersistentDataType.INTEGER) == null
|
||||||
|
? null
|
||||||
|
: NametagActions.values()[item.getPersistentDataContainer().get(nametagActionKey, PersistentDataType.INTEGER)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack createSilenceNametag(ItemStack oldResultItem, String renameText){
|
||||||
|
if(renameText.equals(muteString)) {
|
||||||
|
return this.setNametagAction(oldResultItem, NametagActions.SILENCE);
|
||||||
|
} else if(renameText.equals(unmuteString)) {
|
||||||
|
return this.setNametagAction(oldResultItem, NametagActions.UNSILENCE);
|
||||||
|
}
|
||||||
|
return oldResultItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(new NametagAnvilListener());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user