Commits vergleichen
1 Commits
master
...
FixWarpSou
Autor | SHA1 | Datum | |
---|---|---|---|
|
e9d7836f9a |
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,7 +1,5 @@
|
|||||||
# Build files
|
# Package Files
|
||||||
*.jar
|
*.jar
|
||||||
**/bin
|
|
||||||
**/build
|
|
||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
.gradle
|
.gradle
|
||||||
@ -12,10 +10,6 @@ steamwar.properties
|
|||||||
# IntelliJ IDEA
|
# IntelliJ IDEA
|
||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
plugin.yml
|
|
||||||
|
|
||||||
# Other
|
# Other
|
||||||
lib
|
lib
|
||||||
|
|
||||||
#linkage
|
|
||||||
LinkageUtils.java
|
|
@ -27,8 +27,8 @@ version '1.0'
|
|||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
sourceCompatibility = 17
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 17
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity;
|
||||||
|
import net.minecraft.server.v1_15_R1.*;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class DetonatorEntity15 extends EntityFallingBlock implements AbstractDetonatorEntity {
|
||||||
|
|
||||||
|
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||||
|
private final Vector position;
|
||||||
|
private int references = 0;
|
||||||
|
|
||||||
|
public DetonatorEntity15(World world, Vector position) {
|
||||||
|
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.RED_STAINED_GLASS.getBlockData());
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
this.h(true);
|
||||||
|
this.setNoGravity(true);
|
||||||
|
this.ticksLived = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player) {
|
||||||
|
if (references++ > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.RED_STAINED_GLASS.getBlockData()), ZERO);
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
playerConnection.sendPacket(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
|
||||||
|
playerConnection.sendPacket(packetPlayOutEntityMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player, boolean force) {
|
||||||
|
if (!force && --references > 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
sendDestroy(player);
|
||||||
|
die();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendDestroy(Player player) {
|
||||||
|
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId());
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntity(Player player) {
|
||||||
|
display(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntityDestroy(Player player) {
|
||||||
|
hide(player, false);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
||||||
|
import de.steamwar.bausystem.shared.BaseEntity15;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class SimulatorEntity15 extends BaseEntity15 implements AbstractSimulatorEntity {
|
||||||
|
|
||||||
|
private boolean printed = false;
|
||||||
|
|
||||||
|
public SimulatorEntity15(World world, Vector position, boolean highlight) {
|
||||||
|
super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT);
|
||||||
|
|
||||||
|
this.setNoGravity(true);
|
||||||
|
this.ticksLived = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player) {
|
||||||
|
if (printed) return;
|
||||||
|
printed = true;
|
||||||
|
|
||||||
|
sendEntity(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPosition(Vector position) {
|
||||||
|
this.position = position;
|
||||||
|
setPosition(position.getX(), position.getY(), position.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player, boolean force) {
|
||||||
|
if (!printed) return false;
|
||||||
|
printed = false;
|
||||||
|
|
||||||
|
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
die();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
73
BauSystem_15/src/de/steamwar/bausystem/entities/TraceEntity15.java
Normale Datei
73
BauSystem_15/src/de/steamwar/bausystem/entities/TraceEntity15.java
Normale Datei
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.tracer.AbstractTraceEntity;
|
||||||
|
import de.steamwar.bausystem.shared.BaseEntity15;
|
||||||
|
import de.steamwar.bausystem.shared.ReferenceCounter;
|
||||||
|
import net.minecraft.server.v1_15_R1.ChatComponentText;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class TraceEntity15 extends BaseEntity15 implements AbstractTraceEntity {
|
||||||
|
|
||||||
|
private boolean exploded = false;
|
||||||
|
private ReferenceCounter referenceCounter = new ReferenceCounter();
|
||||||
|
|
||||||
|
public TraceEntity15(World world, Vector position, boolean tnt) {
|
||||||
|
super(world, position, tnt ? Material.TNT : Material.WHITE_STAINED_GLASS);
|
||||||
|
|
||||||
|
this.setNoGravity(true);
|
||||||
|
this.ticksLived = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player, boolean exploded, int ticks) {
|
||||||
|
if (ticks != -1) {
|
||||||
|
this.setCustomNameVisible(true);
|
||||||
|
this.setCustomName(new ChatComponentText(ticks + ""));
|
||||||
|
}
|
||||||
|
if (!this.exploded && exploded) {
|
||||||
|
this.setCustomNameVisible(true);
|
||||||
|
this.setCustomName(new ChatComponentText("Bumm"));
|
||||||
|
this.exploded = true;
|
||||||
|
if (referenceCounter.increment() > 0) {
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
}
|
||||||
|
} else if (referenceCounter.increment() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendEntity(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player, boolean force) {
|
||||||
|
if (!force && referenceCounter.decrement() > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
die();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
60
BauSystem_15/src/de/steamwar/bausystem/entities/WarpEntity15.java
Normale Datei
60
BauSystem_15/src/de/steamwar/bausystem/entities/WarpEntity15.java
Normale Datei
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.warp.AbstractWarpEntity;
|
||||||
|
import de.steamwar.bausystem.shared.BaseArmorStand15;
|
||||||
|
import net.minecraft.server.v1_15_R1.ChatComponentText;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class WarpEntity15 extends BaseArmorStand15 implements AbstractWarpEntity {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public WarpEntity15(World world, Vector position, String name) {
|
||||||
|
super(world, position);
|
||||||
|
setInvisible(true);
|
||||||
|
setSmall(true);
|
||||||
|
this.name = name;
|
||||||
|
this.setNoGravity(true);
|
||||||
|
this.ticksLived = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player) {
|
||||||
|
this.setCustomNameVisible(true);
|
||||||
|
this.setCustomName(new ChatComponentText(name));
|
||||||
|
sendEntity(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player) {
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
die();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
56
BauSystem_15/src/de/steamwar/bausystem/shared/BaseArmorStand15.java
Normale Datei
56
BauSystem_15/src/de/steamwar/bausystem/shared/BaseArmorStand15.java
Normale Datei
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.shared;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_15_R1.*;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class BaseArmorStand15 extends EntityArmorStand implements AbstractEntity {
|
||||||
|
|
||||||
|
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||||
|
|
||||||
|
protected Vector position;
|
||||||
|
|
||||||
|
public BaseArmorStand15(World world, Vector position) {
|
||||||
|
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ());
|
||||||
|
|
||||||
|
this.position = position;
|
||||||
|
setNoGravity(true);
|
||||||
|
ticksLived = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntity(Player player) {
|
||||||
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.ARMOR_STAND, 0, ZERO);
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
playerConnection.sendPacket(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
|
||||||
|
playerConnection.sendPacket(packetPlayOutEntityMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntityDestroy(Player player) {
|
||||||
|
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId());
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
|
||||||
|
}
|
||||||
|
}
|
60
BauSystem_15/src/de/steamwar/bausystem/shared/BaseEntity15.java
Normale Datei
60
BauSystem_15/src/de/steamwar/bausystem/shared/BaseEntity15.java
Normale Datei
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.shared;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_15_R1.*;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class BaseEntity15 extends EntityFallingBlock implements AbstractEntity {
|
||||||
|
|
||||||
|
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||||
|
|
||||||
|
private final IBlockData iBlockData;
|
||||||
|
protected Vector position;
|
||||||
|
|
||||||
|
public BaseEntity15(World world, Vector position, Material blockType) {
|
||||||
|
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), ((CraftBlockData) blockType.createBlockData()).getState());
|
||||||
|
this.iBlockData = ((CraftBlockData) blockType.createBlockData()).getState();
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
this.setNoGravity(true);
|
||||||
|
this.ticksLived = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntity(Player player) {
|
||||||
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(iBlockData), ZERO);
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
playerConnection.sendPacket(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
|
||||||
|
playerConnection.sendPacket(packetPlayOutEntityMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntityDestroy(Player player) {
|
||||||
|
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId());
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
|
||||||
|
}
|
||||||
|
}
|
@ -37,11 +37,14 @@ import com.sk89q.worldedit.function.operation.Operations;
|
|||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.math.transform.AffineTransform;
|
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import de.steamwar.bausystem.region.Color;
|
||||||
|
import de.steamwar.bausystem.region.PasteOptions;
|
||||||
import de.steamwar.bausystem.region.Point;
|
import de.steamwar.bausystem.region.Point;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -57,15 +60,10 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.function.BiPredicate;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class FlatteningWrapper15 implements FlatteningWrapper {
|
public class FlatteningWrapper15 implements FlatteningWrapper.IFlatteningWrapper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNoBook(ItemStack item) {
|
public boolean isNoBook(ItemStack item) {
|
||||||
@ -106,55 +104,76 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
|
|||||||
|
|
||||||
private static final WorldEditPlugin WORLDEDIT_PLUGIN = Objects.requireNonNull((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
private static final WorldEditPlugin WORLDEDIT_PLUGIN = Objects.requireNonNull((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
||||||
private static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0));
|
private static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSelection(Player p, Point minPoint, Point maxPoint) {
|
public void setSelection(Player p, Point minPoint, Point maxPoint) {
|
||||||
WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint)));
|
WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock WOOL2 = Objects.requireNonNull(BlockTypes.YELLOW_WOOL).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock CLAY2 = Objects.requireNonNull(BlockTypes.YELLOW_TERRACOTTA).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock GLAZED = Objects.requireNonNull(BlockTypes.PINK_GLAZED_TERRACOTTA).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock GLASS = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock GLASS2 = Objects.requireNonNull(BlockTypes.YELLOW_STAINED_GLASS).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock GLASS_PANE = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock GLASS_PANE2 = Objects.requireNonNull(BlockTypes.YELLOW_STAINED_GLASS_PANE).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock CONCRETE = Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock CONCRETE2 = Objects.requireNonNull(BlockTypes.YELLOW_CONCRETE).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock CONCRETE_POWDER = Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock();
|
||||||
|
private static final BaseBlock CARPET = Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock();
|
||||||
|
|
||||||
|
private final Map<String, Long> timing = new HashMap<>();
|
||||||
|
|
||||||
|
private void start(String name) {
|
||||||
|
timing.put(name, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
private long stop(String name) {
|
||||||
|
return System.currentTimeMillis() - timing.getOrDefault(name, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Clipboard loadSchematic(File file) {
|
public EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
|
||||||
|
start("clipboardLoad");
|
||||||
Clipboard clipboard;
|
Clipboard clipboard;
|
||||||
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
|
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
|
||||||
clipboard = reader.read();
|
clipboard = reader.read();
|
||||||
} catch (NullPointerException | IOException e) {
|
} catch (NullPointerException | IOException e) {
|
||||||
throw new SecurityException("Bausystem schematic not found", e);
|
throw new SecurityException("Bausystem schematic not found", e);
|
||||||
}
|
}
|
||||||
return clipboard;
|
System.out.println("Clipboard Load: " + stop("clipboardLoad"));
|
||||||
|
|
||||||
|
start("paste");
|
||||||
|
EditSession editSession = paste(clipboard, pastePoint, pasteOptions);
|
||||||
|
System.out.println("Paste: " + stop("paste"));
|
||||||
|
return editSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditSession paste(PasteBuilder pasteBuilder) {
|
public EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
|
||||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||||
Clipboard clipboard = pasteBuilder.getClipboard();
|
start("changeColor");
|
||||||
|
if (pasteOptions.getColor() != Color.YELLOW) {
|
||||||
|
changeColor(clipboard, pasteOptions.getColor());
|
||||||
|
}
|
||||||
|
if (pasteOptions.isOnlyColors()) {
|
||||||
|
Set<String> blocks = new HashSet<>();
|
||||||
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool");
|
||||||
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta");
|
||||||
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta");
|
||||||
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass");
|
||||||
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane");
|
||||||
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete");
|
||||||
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder");
|
||||||
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet");
|
||||||
|
|
||||||
if (!pasteBuilder.getMappers().isEmpty()) {
|
|
||||||
BlockVector3 minimum = clipboard.getRegion().getMinimumPoint();
|
|
||||||
for (int x = 0; x < clipboard.getDimensions().getX(); x++) {
|
|
||||||
for (int y = 0; y < clipboard.getDimensions().getY(); y++) {
|
|
||||||
for (int z = 0; z < clipboard.getDimensions().getZ(); z++) {
|
|
||||||
BlockVector3 pos = minimum.add(x, y, z);
|
|
||||||
pasteBuilder.getMappers().forEach(mapper -> mapper.accept(clipboard, pos));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AtomicReference<BlockVector3> pastePoint = new AtomicReference<>();
|
|
||||||
if (!pasteBuilder.getPredicates().isEmpty()) {
|
|
||||||
e.setMask(new Mask() {
|
e.setMask(new Mask() {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(BlockVector3 blockVector3) {
|
public boolean test(BlockVector3 blockVector3) {
|
||||||
BaseBlock block = clipboard.getFullBlock(blockVector3.subtract(pastePoint.get()).add(clipboard.getRegion().getMinimumPoint()));
|
BaseBlock block = clipboard.getFullBlock(blockVector3);
|
||||||
String blockName = block.getBlockType().toString().toLowerCase();
|
String blockName = block.toString().toLowerCase();
|
||||||
for (BiPredicate<BaseBlock, String> predicate : pasteBuilder.getPredicates()) {
|
return blocks.contains(blockName);
|
||||||
if (!predicate.test(block, blockName)) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mask copy() {
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -162,28 +181,38 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
|
|||||||
public Mask2D toMask2D() {
|
public Mask2D toMask2D() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Mask copy() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
System.out.println("ChangeColor: " + stop("changeColor"));
|
||||||
|
|
||||||
|
start("transform");
|
||||||
ClipboardHolder ch = new ClipboardHolder(clipboard);
|
ClipboardHolder ch = new ClipboardHolder(clipboard);
|
||||||
BlockVector3 dimensions = clipboard.getDimensions();
|
BlockVector3 dimensions = clipboard.getDimensions();
|
||||||
BlockVector3 v = BlockVector3.at(pasteBuilder.getPastPoint().getX(), pasteBuilder.getPastPoint().getY(), pasteBuilder.getPastPoint().getZ());
|
BlockVector3 v = BlockVector3.at(pastePoint.getX(), pastePoint.getY(), pastePoint.getZ());
|
||||||
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
||||||
if (pasteBuilder.isRotate()) {
|
if (pasteOptions.isRotate()) {
|
||||||
ch.setTransform(new AffineTransform().rotateY(180));
|
ch.setTransform(new AffineTransform().rotateY(180));
|
||||||
v = v.add(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset.multiply(-1, 1, -1)).subtract(0, 0, 1);
|
v = v.add(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset.multiply(-1, 1, -1)).subtract(0, 0, 1);
|
||||||
} else {
|
} else {
|
||||||
v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset);
|
v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset);
|
||||||
}
|
}
|
||||||
pastePoint.set(v);
|
System.out.println("Transform: " + stop("transform"));
|
||||||
|
|
||||||
if (pasteBuilder.isReset()) {
|
start("reset");
|
||||||
e.setBlocks(new CuboidRegion(toBlockVector3(pasteBuilder.getMinPoint()), toBlockVector3(pasteBuilder.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock());
|
if (pasteOptions.isReset()) {
|
||||||
if (pasteBuilder.getWaterLevel() != 0) {
|
e.setBlocks((Region) new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock());
|
||||||
e.setBlocks(new CuboidRegion(toBlockVector3(pasteBuilder.getMinPoint()), toBlockVector3(pasteBuilder.getMaxPoint()).withY(pasteBuilder.getWaterLevel())), Objects.requireNonNull(BlockTypes.WATER).getDefaultState().toBaseBlock());
|
if (pasteOptions.getWaterLevel() != 0) {
|
||||||
|
e.setBlocks((Region) new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint()).withY(pasteOptions.getWaterLevel())), Objects.requireNonNull(BlockTypes.WATER).getDefaultState().toBaseBlock());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(pasteBuilder.isIgnoreAir()).build());
|
System.out.println("Reset: " + stop("reset"));
|
||||||
|
start("operation");
|
||||||
|
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(pasteOptions.isIgnoreAir()).build());
|
||||||
|
System.out.println("Operation: " + stop("operation"));
|
||||||
return e;
|
return e;
|
||||||
} catch (WorldEditException e) {
|
} catch (WorldEditException e) {
|
||||||
throw new SecurityException(e.getMessage(), e);
|
throw new SecurityException(e.getMessage(), e);
|
||||||
@ -191,7 +220,56 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Clipboard copy(Point minPoint, Point maxPoint, Point copyPoint) {
|
public void changeColor(Clipboard clipboard, Color color) throws WorldEditException {
|
||||||
|
BlockVector3 minimum = clipboard.getRegion().getMinimumPoint();
|
||||||
|
BaseBlock wool = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock();
|
||||||
|
BaseBlock clay = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_terracotta")).getDefaultState().toBaseBlock();
|
||||||
|
BaseBlock glazed = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_glazed_terracotta")).getDefaultState().toBaseBlock();
|
||||||
|
BaseBlock glass = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass")).getDefaultState().toBaseBlock();
|
||||||
|
BaseBlock glassPane = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass_pane")).getDefaultState().toBaseBlock();
|
||||||
|
BaseBlock carpet = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_carpet")).getDefaultState().toBaseBlock();
|
||||||
|
BaseBlock concrete = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_concrete")).getDefaultState().toBaseBlock();
|
||||||
|
BaseBlock concretePowder = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_concrete_powder")).getDefaultState().toBaseBlock();
|
||||||
|
|
||||||
|
for (int x = 0; x < clipboard.getDimensions().getX(); x++) {
|
||||||
|
for (int y = 0; y < clipboard.getDimensions().getY(); y++) {
|
||||||
|
for (int z = 0; z < clipboard.getDimensions().getZ(); z++) {
|
||||||
|
BlockVector3 pos = minimum.add(x, y, z);
|
||||||
|
BaseBlock block = clipboard.getFullBlock(pos);
|
||||||
|
if (block.equals(WOOL)) {
|
||||||
|
clipboard.setBlock(pos, wool);
|
||||||
|
} else if (block.equals(WOOL2)) {
|
||||||
|
clipboard.setBlock(pos, wool);
|
||||||
|
} else if (block.equals(CLAY)) {
|
||||||
|
clipboard.setBlock(pos, clay);
|
||||||
|
} else if (block.equals(CLAY2)) {
|
||||||
|
clipboard.setBlock(pos, clay);
|
||||||
|
} else if (block.equals(GLAZED)) {
|
||||||
|
clipboard.setBlock(pos, glazed);
|
||||||
|
} else if (block.equals(GLASS)) {
|
||||||
|
clipboard.setBlock(pos, glass);
|
||||||
|
} else if (block.equals(GLASS2)) {
|
||||||
|
clipboard.setBlock(pos, glass);
|
||||||
|
} else if (block.equals(GLASS_PANE)) {
|
||||||
|
clipboard.setBlock(pos, glassPane);
|
||||||
|
} else if (block.equals(GLASS_PANE2)) {
|
||||||
|
clipboard.setBlock(pos, glassPane);
|
||||||
|
} else if (block.equals(CARPET)) {
|
||||||
|
clipboard.setBlock(pos, carpet);
|
||||||
|
} else if (block.equals(CONCRETE)) {
|
||||||
|
clipboard.setBlock(pos, concrete);
|
||||||
|
} else if (block.equals(CONCRETE2)) {
|
||||||
|
clipboard.setBlock(pos, concrete);
|
||||||
|
} else if (block.equals(CONCRETE_POWDER)) {
|
||||||
|
clipboard.setBlock(pos, concretePowder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean backup(Point minPoint, Point maxPoint, File file) {
|
||||||
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0));
|
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||||
CuboidRegion region = new CuboidRegion(bukkitWorld, toBlockVector3(minPoint), toBlockVector3(maxPoint));
|
CuboidRegion region = new CuboidRegion(bukkitWorld, toBlockVector3(minPoint), toBlockVector3(maxPoint));
|
||||||
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
||||||
@ -204,21 +282,12 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
|
|||||||
copy.setCopyingBiomes(false);
|
copy.setCopyingBiomes(false);
|
||||||
|
|
||||||
Operations.complete(copy);
|
Operations.complete(copy);
|
||||||
clipboard.setOrigin(toBlockVector3(copyPoint));
|
|
||||||
return clipboard;
|
|
||||||
} catch (WorldEditException e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean backup(Point minPoint, Point maxPoint, File file) {
|
|
||||||
Clipboard clipboard = copy(minPoint, maxPoint, minPoint);
|
|
||||||
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
|
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
|
||||||
writer.write(clipboard);
|
writer.write(clipboard);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (WorldEditException | IOException e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -240,4 +309,19 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
|
|||||||
|
|
||||||
return ((Waterlogged) data).isWaterlogged();
|
return ((Waterlogged) data).isWaterlogged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getTraceShowMaterial() {
|
||||||
|
return Material.LIME_CONCRETE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getTraceHideMaterial() {
|
||||||
|
return Material.RED_CONCRETE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getTraceXZMaterial() {
|
||||||
|
return Material.QUARTZ_SLAB;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,20 @@
|
|||||||
package de.steamwar.bausystem.utils;
|
package de.steamwar.bausystem.utils;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import de.steamwar.bausystem.entities.DetonatorEntity15;
|
||||||
|
import de.steamwar.bausystem.entities.SimulatorEntity15;
|
||||||
|
import de.steamwar.bausystem.entities.TraceEntity15;
|
||||||
|
import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity;
|
||||||
import de.steamwar.bausystem.features.util.NoClipCommand;
|
import de.steamwar.bausystem.features.util.NoClipCommand;
|
||||||
|
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
||||||
|
import de.steamwar.bausystem.features.tracer.AbstractTraceEntity;
|
||||||
|
import de.steamwar.bausystem.features.warp.AbstractWarpEntity;
|
||||||
|
import de.steamwar.bausystem.entities.WarpEntity15;
|
||||||
import net.minecraft.server.v1_15_R1.*;
|
import net.minecraft.server.v1_15_R1.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
@ -32,15 +41,15 @@ import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.LongSupplier;
|
import java.util.function.LongSupplier;
|
||||||
|
|
||||||
public class NMSWrapper15 implements NMSWrapper {
|
public class NMSWrapper15 implements NMSWrapper.INMSWrapper {
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
|
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void setInternalGameMode(Player player, GameMode gameMode) {
|
public void setInternalGameMode(Player player, GameMode gameMode) {
|
||||||
@ -48,23 +57,37 @@ public class NMSWrapper15 implements NMSWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSlotToItemStack(Player player, Object o) {
|
public void init(LongSupplier longSupplier) {
|
||||||
PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot = (PacketPlayInSetCreativeSlot) o;
|
SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong();
|
||||||
int index = packetPlayInSetCreativeSlot.b();
|
|
||||||
if (index >= 36 && index <= 44) {
|
|
||||||
index -= 36;
|
|
||||||
} else if (index > 44) {
|
|
||||||
index -= 5;
|
|
||||||
} else if (index <= 8) {
|
|
||||||
index = index - 8 + 36;
|
|
||||||
}
|
}
|
||||||
player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.getItemStack()));
|
|
||||||
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
private static final List<Packet<?>> packets = new ArrayList<>();
|
||||||
player.updateInventory();
|
private static final Vec3D noMotion = new Vec3D(0, 0, 0);
|
||||||
|
@Override
|
||||||
|
public void createTickCache(World world) {
|
||||||
|
packets.clear();
|
||||||
|
world.getEntities().stream().filter(entity -> !(entity instanceof Player)).forEach(entity -> {
|
||||||
|
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
|
||||||
|
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
|
||||||
|
|
||||||
|
if (entity instanceof TNTPrimed) {
|
||||||
|
net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle();
|
||||||
|
packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTickPackets() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
|
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
for (Packet<?> p : packets) {
|
||||||
|
connection.sendPacket(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<Integer> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0);
|
private static final Reflection.FieldAccessor<Integer> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGameStateChangeReason(Object packet) {
|
public void setGameStateChangeReason(Object packet) {
|
||||||
gameStateChangeReason.set(packet, 3);
|
gameStateChangeReason.set(packet, 3);
|
||||||
@ -76,13 +99,17 @@ public class NMSWrapper15 implements NMSWrapper {
|
|||||||
((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true;
|
((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle tntPositionParticle() {
|
||||||
|
return Particle.BARRIER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Material pathMaterial() {
|
public Material pathMaterial() {
|
||||||
return Material.GRASS_PATH;
|
return Material.GRASS_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int threshold = 2048;
|
private static final int threshold = 2048;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkItemStack(ItemStack item) {
|
public boolean checkItemStack(ItemStack item) {
|
||||||
net.minecraft.server.v1_15_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
net.minecraft.server.v1_15_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||||
@ -120,16 +147,23 @@ public class NMSWrapper15 implements NMSWrapper {
|
|||||||
return invalid;
|
return invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion");
|
@Override
|
||||||
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0);
|
public AbstractWarpEntity createWarp(World world, Vector position, String name) {
|
||||||
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1);
|
return new WarpEntity15(world, position, name);
|
||||||
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2);
|
}
|
||||||
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0);
|
|
||||||
private final Reflection.FieldAccessor<List> e = Reflection.getField(explosionPacket, List.class, 0);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resetExplosionKnockback(Object packet) {
|
public AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight) {
|
||||||
PacketPlayOutExplosion packetPlayOutExplosion = (PacketPlayOutExplosion) packet;
|
return new SimulatorEntity15(world, tntPosition, highlight);
|
||||||
return new PacketPlayOutExplosion(a.get(packetPlayOutExplosion), b.get(packetPlayOutExplosion), c.get(packetPlayOutExplosion), d.get(packetPlayOutExplosion), e.get(packetPlayOutExplosion), Vec3D.a);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractDetonatorEntity constructDetonator(World world, Vector position) {
|
||||||
|
return new DetonatorEntity15(world, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt) {
|
||||||
|
return new TraceEntity15(world, tntPosition, tnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
|
|
||||||
public class PlaceItemWrapper15 implements PlaceItemWrapper {
|
|
||||||
|
|
||||||
public PlaceItemWrapper15() {
|
|
||||||
for (Material material : Material.values()) {
|
|
||||||
if (!material.isBlock()) continue;
|
|
||||||
if (material.isLegacy()) continue;
|
|
||||||
|
|
||||||
String nonWall = material.name().replace("_WALL_", "").replace("WALL_", "").replace("_WALL", "");
|
|
||||||
try {
|
|
||||||
Material nonWallMaterial = Material.valueOf(nonWall);
|
|
||||||
if (nonWallMaterial != material && nonWallMaterial.isItem() && !nonWallMaterial.isBlock()) {
|
|
||||||
BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.put(nonWallMaterial, material);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ITEM_MATERIAL_TO_BLOCK_MATERIAL.put(Material.REDSTONE, Material.REDSTONE_WIRE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
|
||||||
import de.steamwar.bausystem.utils.PlayerMovementWrapper;
|
|
||||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_15_R1.PacketPlayInFlying;
|
|
||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntity;
|
|
||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport;
|
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class PlayerMovementWrapper15 implements PlayerMovementWrapper {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPosition(Player player, Object object) {
|
|
||||||
PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object);
|
|
||||||
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
|
|
||||||
if (Float.isNaN(packetPlayInFlying.a(Float.NaN))) {
|
|
||||||
entityPlayer.e(packetPlayInFlying.a(0.0), packetPlayInFlying.b(0.0), packetPlayInFlying.c(0.0));
|
|
||||||
} else {
|
|
||||||
entityPlayer.setLocation(packetPlayInFlying.a(0.0), packetPlayInFlying.b(0.0), packetPlayInFlying.c(0.0), packetPlayInFlying.a(0F), packetPlayInFlying.b(0F));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convertToOut(Player player, Object object) {
|
|
||||||
PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object);
|
|
||||||
Object packet = Reflection.newInstance(teleportPacket);
|
|
||||||
teleportEntity.set(packet, player.getEntityId());
|
|
||||||
teleportPosition.set(packet, packetPlayInFlying.a(0.0), packetPlayInFlying.b(0.0), packetPlayInFlying.c(0.0));
|
|
||||||
if (Float.isNaN(packetPlayInFlying.a(Float.NaN))) {
|
|
||||||
teleportYaw.set(packet, rotToByte(player.getLocation().getYaw()));
|
|
||||||
teleportPitch.set(packet, rotToByte(player.getLocation().getPitch()));
|
|
||||||
} else {
|
|
||||||
teleportYaw.set(packet, rotToByte(packetPlayInFlying.a(0.0F)));
|
|
||||||
teleportPitch.set(packet, rotToByte(packetPlayInFlying.b(0.0F)));
|
|
||||||
}
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,25 +17,17 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.linkage.types;
|
package de.steamwar.bausystem.utils;
|
||||||
|
|
||||||
import de.steamwar.linkage.LinkageType;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import de.steamwar.linkage.plan.BuildPlan;
|
import com.mojang.authlib.GameProfile;
|
||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
import de.steamwar.bausystem.features.util.NoClipCommand;
|
||||||
|
|
||||||
import javax.lang.model.element.TypeElement;
|
public class ProtocolWrapper15 implements ProtocolWrapper {
|
||||||
|
|
||||||
public class FAWEMaskParser_GENERIC implements LinkageType {
|
|
||||||
|
|
||||||
|
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(NoClipCommand.playerInfoDataClass, NoClipCommand.playerInfoPacket, GameProfile.class, int.class, NoClipCommand.enumGamemode, NoClipCommand.iChatBaseComponent);
|
||||||
@Override
|
@Override
|
||||||
public String method() {
|
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) {
|
||||||
return "link";
|
return playerInfoDataConstructor.invoke(packet, profile, 0, mode, null);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
|
|
||||||
methodBuilder.addLine("if (org.bukkit.Bukkit.getPluginManager().getPlugin(\"FastAsyncWorldEdit\") != null) {");
|
|
||||||
methodBuilder.addLine(" " + s + ";");
|
|
||||||
methodBuilder.addLine("}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
|
||||||
|
|
||||||
public class TickListener15 implements TickListener {
|
|
||||||
}
|
|
@ -27,8 +27,8 @@ version '1.0'
|
|||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
sourceCompatibility = 17
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 17
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
|
||||||
|
import net.minecraft.server.network.PlayerConnection;
|
||||||
|
import net.minecraft.world.entity.EntityTypes;
|
||||||
|
import net.minecraft.world.entity.item.EntityFallingBlock;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
import net.minecraft.world.phys.Vec3D;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class DetonatorEntity18 extends EntityFallingBlock implements AbstractDetonatorEntity {
|
||||||
|
|
||||||
|
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||||
|
private final Vector position;
|
||||||
|
private int references = 0;
|
||||||
|
|
||||||
|
public DetonatorEntity18(World world, Vector position) {
|
||||||
|
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.du.n());
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
this.h(true);
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return ae();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player) {
|
||||||
|
if (references++ > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), cm(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.C, Block.i(Blocks.du.n()), ZERO);
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b;
|
||||||
|
playerConnection.a(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), Y, true);
|
||||||
|
playerConnection.a(packetPlayOutEntityMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player, boolean force) {
|
||||||
|
if (!force && --references > 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
sendDestroy(player);
|
||||||
|
ag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendDestroy(Player player) {
|
||||||
|
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId());
|
||||||
|
((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntity(Player player) {
|
||||||
|
display(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntityDestroy(Player player) {
|
||||||
|
hide(player, false);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
||||||
|
import de.steamwar.bausystem.shared.BaseEntity18;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class SimulatorEntity18 extends BaseEntity18 implements AbstractSimulatorEntity {
|
||||||
|
|
||||||
|
private boolean printed = false;
|
||||||
|
|
||||||
|
public SimulatorEntity18(World world, Vector position, boolean highlight) {
|
||||||
|
super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT);
|
||||||
|
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return ae();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player) {
|
||||||
|
if (printed) return;
|
||||||
|
printed = true;
|
||||||
|
|
||||||
|
sendEntity(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPosition(Vector position) {
|
||||||
|
this.position = position;
|
||||||
|
e(position.getX(), position.getY(), position.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player, boolean force) {
|
||||||
|
if (!printed) return false;
|
||||||
|
printed = false;
|
||||||
|
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
ag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
73
BauSystem_18/src/de/steamwar/bausystem/entities/TraceEntity18.java
Normale Datei
73
BauSystem_18/src/de/steamwar/bausystem/entities/TraceEntity18.java
Normale Datei
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.tracer.AbstractTraceEntity;
|
||||||
|
import de.steamwar.bausystem.shared.BaseEntity18;
|
||||||
|
import de.steamwar.bausystem.shared.ReferenceCounter;
|
||||||
|
import net.minecraft.network.chat.ChatComponentText;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class TraceEntity18 extends BaseEntity18 implements AbstractTraceEntity {
|
||||||
|
|
||||||
|
private boolean exploded = false;
|
||||||
|
private ReferenceCounter referenceCounter = new ReferenceCounter();
|
||||||
|
|
||||||
|
public TraceEntity18(World world, Vector position, boolean tnt) {
|
||||||
|
super(world, position, tnt ? Material.TNT : Material.WHITE_STAINED_GLASS);
|
||||||
|
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player, boolean exploded, int ticks) {
|
||||||
|
if (ticks != -1) {
|
||||||
|
this.n(true);
|
||||||
|
this.a(new ChatComponentText(ticks + ""));
|
||||||
|
}
|
||||||
|
if (!this.exploded && exploded) {
|
||||||
|
this.n(true);
|
||||||
|
this.a(new ChatComponentText("Bumm"));
|
||||||
|
this.exploded = true;
|
||||||
|
if (referenceCounter.increment() > 0) {
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
}
|
||||||
|
} else if (referenceCounter.increment() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendEntity(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player, boolean force) {
|
||||||
|
if (!force && referenceCounter.decrement() > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
ag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
60
BauSystem_18/src/de/steamwar/bausystem/entities/WarpEntity18.java
Normale Datei
60
BauSystem_18/src/de/steamwar/bausystem/entities/WarpEntity18.java
Normale Datei
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.warp.AbstractWarpEntity;
|
||||||
|
import de.steamwar.bausystem.shared.BaseArmorStand18;
|
||||||
|
import net.minecraft.network.chat.ChatComponentText;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class WarpEntity18 extends BaseArmorStand18 implements AbstractWarpEntity {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public WarpEntity18(World world, Vector position, String name) {
|
||||||
|
super(world, position);
|
||||||
|
this.j(true);
|
||||||
|
this.a(true);
|
||||||
|
this.name = name;
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player) {
|
||||||
|
this.n(true);
|
||||||
|
this.a(new ChatComponentText(name));
|
||||||
|
sendEntity(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player) {
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
ag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
62
BauSystem_18/src/de/steamwar/bausystem/shared/BaseArmorStand18.java
Normale Datei
62
BauSystem_18/src/de/steamwar/bausystem/shared/BaseArmorStand18.java
Normale Datei
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.shared;
|
||||||
|
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
|
||||||
|
import net.minecraft.server.network.PlayerConnection;
|
||||||
|
import net.minecraft.world.entity.EntityTypes;
|
||||||
|
import net.minecraft.world.entity.decoration.EntityArmorStand;
|
||||||
|
import net.minecraft.world.phys.Vec3D;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class BaseArmorStand18 extends EntityArmorStand implements AbstractEntity {
|
||||||
|
|
||||||
|
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||||
|
|
||||||
|
protected Vector position;
|
||||||
|
|
||||||
|
public BaseArmorStand18(World world, Vector position) {
|
||||||
|
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ());
|
||||||
|
|
||||||
|
this.position = position;
|
||||||
|
e(true);
|
||||||
|
S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntity(Player player) {
|
||||||
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), cm(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.c, 0, ZERO);
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b;
|
||||||
|
playerConnection.a(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true);
|
||||||
|
playerConnection.a(packetPlayOutEntityMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntityDestroy(Player player) {
|
||||||
|
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(ae());
|
||||||
|
((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy);
|
||||||
|
}
|
||||||
|
}
|
68
BauSystem_18/src/de/steamwar/bausystem/shared/BaseEntity18.java
Normale Datei
68
BauSystem_18/src/de/steamwar/bausystem/shared/BaseEntity18.java
Normale Datei
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.shared;
|
||||||
|
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
|
||||||
|
import net.minecraft.server.network.PlayerConnection;
|
||||||
|
import net.minecraft.world.entity.EntityTypes;
|
||||||
|
import net.minecraft.world.entity.item.EntityFallingBlock;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.state.IBlockData;
|
||||||
|
import net.minecraft.world.phys.Vec3D;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData;
|
||||||
|
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class BaseEntity18 extends EntityFallingBlock implements AbstractEntity {
|
||||||
|
|
||||||
|
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||||
|
|
||||||
|
private final IBlockData iBlockData;
|
||||||
|
protected Vector position;
|
||||||
|
|
||||||
|
public BaseEntity18(World world, Vector position, Material blockType) {
|
||||||
|
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), ((CraftBlockData) blockType.createBlockData()).getState());
|
||||||
|
this.iBlockData = ((CraftBlockData) blockType.createBlockData()).getState();
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntity(Player player) {
|
||||||
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), cm(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.C, Block.i(iBlockData), ZERO);
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b;
|
||||||
|
playerConnection.a(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true);
|
||||||
|
playerConnection.a(packetPlayOutEntityMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntityDestroy(Player player) {
|
||||||
|
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(ae());
|
||||||
|
((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy);
|
||||||
|
}
|
||||||
|
}
|
@ -21,35 +21,43 @@ package de.steamwar.bausystem.utils;
|
|||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
|
import de.steamwar.bausystem.entities.DetonatorEntity18;
|
||||||
|
import de.steamwar.bausystem.entities.SimulatorEntity18;
|
||||||
|
import de.steamwar.bausystem.entities.TraceEntity18;
|
||||||
|
import de.steamwar.bausystem.entities.WarpEntity18;
|
||||||
|
import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity;
|
||||||
import de.steamwar.bausystem.features.util.NoClipCommand;
|
import de.steamwar.bausystem.features.util.NoClipCommand;
|
||||||
|
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
||||||
|
import de.steamwar.bausystem.features.tracer.AbstractTraceEntity;
|
||||||
|
import de.steamwar.bausystem.features.warp.AbstractWarpEntity;
|
||||||
import net.minecraft.SystemUtils;
|
import net.minecraft.SystemUtils;
|
||||||
import net.minecraft.nbt.NBTBase;
|
import net.minecraft.nbt.NBTBase;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange;
|
||||||
import net.minecraft.server.level.PlayerInteractManager;
|
import net.minecraft.server.level.PlayerInteractManager;
|
||||||
import net.minecraft.world.level.EnumGamemode;
|
import net.minecraft.world.level.EnumGamemode;
|
||||||
import net.minecraft.world.phys.Vec3D;
|
import net.minecraft.world.phys.Vec3D;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.LongSupplier;
|
import java.util.function.LongSupplier;
|
||||||
|
|
||||||
public class NMSWrapper18 implements NMSWrapper {
|
public class NMSWrapper18 implements NMSWrapper.INMSWrapper {
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
|
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void setInternalGameMode(Player player, GameMode gameMode) {
|
public void setInternalGameMode(Player player, GameMode gameMode) {
|
||||||
@ -58,23 +66,36 @@ public class NMSWrapper18 implements NMSWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSlotToItemStack(Player player, Object o) {
|
public void init(LongSupplier longSupplier) {
|
||||||
PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot = (PacketPlayInSetCreativeSlot) o;
|
SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong();
|
||||||
int index = packetPlayInSetCreativeSlot.b();
|
|
||||||
if (index >= 36 && index <= 44) {
|
|
||||||
index -= 36;
|
|
||||||
} else if (index > 44) {
|
|
||||||
index -= 5;
|
|
||||||
} else if (index <= 8) {
|
|
||||||
index = index - 8 + 36;
|
|
||||||
}
|
}
|
||||||
player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.c()));
|
|
||||||
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
private static final List<Packet<?>> packets = new ArrayList<>();
|
||||||
player.updateInventory();
|
private static final Vec3D noMotion = new Vec3D(0, 0, 0);
|
||||||
|
@Override
|
||||||
|
public void createTickCache(World world) {
|
||||||
|
packets.clear();
|
||||||
|
world.getEntities().stream().filter(entity -> !(entity instanceof Player)).forEach(entity -> {
|
||||||
|
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
|
||||||
|
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
|
||||||
|
|
||||||
|
if (entity instanceof TNTPrimed) {
|
||||||
|
net.minecraft.world.entity.Entity serverEntity = ((CraftEntity) entity).getHandle();
|
||||||
|
packets.add(new PacketPlayOutEntityMetadata(serverEntity.ae(), serverEntity.ai(), true));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTickPackets() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
|
for (Packet<?> p : packets) {
|
||||||
|
TinyProtocol.instance.sendPacket(player, p);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
|
private static final Reflection.FieldAccessor<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGameStateChangeReason(Object packet) {
|
public void setGameStateChangeReason(Object packet) {
|
||||||
gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d);
|
gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d);
|
||||||
@ -86,13 +107,17 @@ public class NMSWrapper18 implements NMSWrapper {
|
|||||||
((CraftPlayer) player).getHandle().fs().e = true;
|
((CraftPlayer) player).getHandle().fs().e = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle tntPositionParticle() {
|
||||||
|
return Particle.BLOCK_MARKER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Material pathMaterial() {
|
public Material pathMaterial() {
|
||||||
return Material.DIRT_PATH;
|
return Material.DIRT_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int threshold = 2048;
|
private static final int threshold = 2048;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkItemStack(ItemStack item) {
|
public boolean checkItemStack(ItemStack item) {
|
||||||
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||||
@ -130,16 +155,23 @@ public class NMSWrapper18 implements NMSWrapper {
|
|||||||
return invalid;
|
return invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion");
|
@Override
|
||||||
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0);
|
public AbstractWarpEntity createWarp(World world, Vector position, String name) {
|
||||||
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1);
|
return new WarpEntity18(world, position, name);
|
||||||
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2);
|
}
|
||||||
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0);
|
|
||||||
private final Reflection.FieldAccessor<List> e = Reflection.getField(explosionPacket, List.class, 0);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resetExplosionKnockback(Object packet) {
|
public AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight) {
|
||||||
PacketPlayOutExplosion packetPlayOutExplosion = (PacketPlayOutExplosion) packet;
|
return new SimulatorEntity18(world, tntPosition, highlight);
|
||||||
return new PacketPlayOutExplosion(a.get(packetPlayOutExplosion), b.get(packetPlayOutExplosion), c.get(packetPlayOutExplosion), d.get(packetPlayOutExplosion), e.get(packetPlayOutExplosion), null);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractDetonatorEntity constructDetonator(World world, Vector position) {
|
||||||
|
return new DetonatorEntity18(world, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt) {
|
||||||
|
return new TraceEntity18(world, tntPosition, tnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
|
||||||
import de.steamwar.bausystem.utils.PlayerMovementWrapper;
|
|
||||||
import net.minecraft.network.protocol.game.PacketPlayInFlying;
|
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
|
||||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class PlayerMovementWrapper18 implements PlayerMovementWrapper {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPosition(Player player, Object object) {
|
|
||||||
PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object);
|
|
||||||
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
|
|
||||||
if (packetPlayInFlying.h) {
|
|
||||||
entityPlayer.b(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c, packetPlayInFlying.d, packetPlayInFlying.e);
|
|
||||||
} else {
|
|
||||||
entityPlayer.e(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convertToOut(Player player, Object object) {
|
|
||||||
PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object);
|
|
||||||
Object packet = Reflection.newInstance(teleportPacket);
|
|
||||||
teleportEntity.set(packet, player.getEntityId());
|
|
||||||
teleportPosition.set(packet, packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c);
|
|
||||||
if (packetPlayInFlying.h) {
|
|
||||||
teleportYaw.set(packet, rotToByte(player.getLocation().getYaw()));
|
|
||||||
teleportPitch.set(packet, rotToByte(player.getLocation().getPitch()));
|
|
||||||
} else {
|
|
||||||
teleportYaw.set(packet, rotToByte(packetPlayInFlying.d));
|
|
||||||
teleportPitch.set(packet, rotToByte(packetPlayInFlying.e));
|
|
||||||
}
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,22 +17,17 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.world;
|
package de.steamwar.bausystem.utils;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.mojang.authlib.GameProfile;
|
||||||
import de.steamwar.bausystem.utils.NMSWrapper;
|
import de.steamwar.bausystem.features.util.NoClipCommand;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.linkage.api.Plain;
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
|
|
||||||
@Linked
|
public class ProtocolWrapper18 implements ProtocolWrapper {
|
||||||
public class NoCreativeKnockback implements Plain {
|
|
||||||
|
|
||||||
public NoCreativeKnockback() {
|
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(NoClipCommand.playerInfoDataClass, GameProfile.class, int.class, NoClipCommand.enumGamemode, NoClipCommand.iChatBaseComponent);
|
||||||
TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"), (player, o) -> {
|
@Override
|
||||||
if (player.getGameMode() != GameMode.CREATIVE) return o;
|
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) {
|
||||||
return NMSWrapper.impl.resetExplosionKnockback(o);
|
return playerInfoDataConstructor.invoke(profile, 0, mode, null);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,8 +27,8 @@ version '1.0'
|
|||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
sourceCompatibility = 17
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 17
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
@ -51,7 +51,6 @@ dependencies {
|
|||||||
implementation project(":BauSystem_Main")
|
implementation project(":BauSystem_Main")
|
||||||
|
|
||||||
compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
|
compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT'
|
|
||||||
compileOnly 'it.unimi.dsi:fastutil:8.5.6'
|
compileOnly 'it.unimi.dsi:fastutil:8.5.6'
|
||||||
compileOnly 'com.mojang:datafixerupper:4.0.26'
|
compileOnly 'com.mojang:datafixerupper:4.0.26'
|
||||||
compileOnly 'io.netty:netty-all:4.1.68.Final'
|
compileOnly 'io.netty:netty-all:4.1.68.Final'
|
||||||
|
124
BauSystem_19/src/de/steamwar/bausystem/entities/DetonatorEntity19.java
Normale Datei
124
BauSystem_19/src/de/steamwar/bausystem/entities/DetonatorEntity19.java
Normale Datei
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
|
||||||
|
import net.minecraft.server.network.PlayerConnection;
|
||||||
|
import net.minecraft.world.entity.EntityTypes;
|
||||||
|
import net.minecraft.world.entity.item.EntityFallingBlock;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.state.IBlockData;
|
||||||
|
import net.minecraft.world.phys.Vec3D;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
public class DetonatorEntity19 extends EntityFallingBlock implements AbstractDetonatorEntity {
|
||||||
|
|
||||||
|
private static final Field ao;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
ao = EntityFallingBlock.class.getDeclaredField("ao");
|
||||||
|
ao.setAccessible(true);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||||
|
private final Vector position;
|
||||||
|
private int references = 0;
|
||||||
|
private IBlockData iBlockData;
|
||||||
|
|
||||||
|
public DetonatorEntity19(World world, Vector position) {
|
||||||
|
super(EntityTypes.E, ((CraftWorld) world).getHandle());
|
||||||
|
try {
|
||||||
|
ao.set(this, ((CraftBlockData) Material.RED_STAINED_GLASS.createBlockData()).getState());
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
this.q = true;
|
||||||
|
e(position.getX(), position.getY(), position.getZ());
|
||||||
|
f(Vec3D.b);
|
||||||
|
t = position.getX();
|
||||||
|
u = position.getY();
|
||||||
|
v = position.getZ();
|
||||||
|
a(this.db());
|
||||||
|
|
||||||
|
this.iBlockData = ((CraftBlockData) Material.RED_STAINED_GLASS.createBlockData()).getState();
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return ae();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player) {
|
||||||
|
if (references++ > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), cp(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.E, Block.i(iBlockData), ZERO, 0.0);
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b;
|
||||||
|
playerConnection.a(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), Y, true);
|
||||||
|
playerConnection.a(packetPlayOutEntityMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player, boolean force) {
|
||||||
|
if (!force && --references > 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
sendDestroy(player);
|
||||||
|
ag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendDestroy(Player player) {
|
||||||
|
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId());
|
||||||
|
((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntity(Player player) {
|
||||||
|
display(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntityDestroy(Player player) {
|
||||||
|
hide(player, false);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
||||||
|
import de.steamwar.bausystem.shared.BaseEntity19;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class SimulatorEntity19 extends BaseEntity19 implements AbstractSimulatorEntity {
|
||||||
|
|
||||||
|
private boolean printed = false;
|
||||||
|
|
||||||
|
public SimulatorEntity19(World world, Vector position, boolean highlight) {
|
||||||
|
super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT);
|
||||||
|
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return ae();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player) {
|
||||||
|
if (printed) return;
|
||||||
|
printed = true;
|
||||||
|
|
||||||
|
sendEntity(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPosition(Vector position) {
|
||||||
|
this.position = position;
|
||||||
|
e(position.getX(), position.getY(), position.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player, boolean force) {
|
||||||
|
if (!printed) return false;
|
||||||
|
printed = false;
|
||||||
|
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
ag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
74
BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java
Normale Datei
74
BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java
Normale Datei
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.tracer.AbstractTraceEntity;
|
||||||
|
import de.steamwar.bausystem.shared.BaseEntity19;
|
||||||
|
import de.steamwar.bausystem.shared.ReferenceCounter;
|
||||||
|
import net.minecraft.network.chat.IChatMutableComponent;
|
||||||
|
import net.minecraft.network.chat.contents.LiteralContents;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class TraceEntity19 extends BaseEntity19 implements AbstractTraceEntity {
|
||||||
|
|
||||||
|
private boolean exploded = false;
|
||||||
|
private ReferenceCounter referenceCounter = new ReferenceCounter();
|
||||||
|
|
||||||
|
public TraceEntity19(World world, Vector position, boolean tnt) {
|
||||||
|
super(world, position, tnt ? Material.TNT : Material.WHITE_STAINED_GLASS);
|
||||||
|
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player, boolean exploded, int ticks) {
|
||||||
|
if (ticks != -1) {
|
||||||
|
this.n(true);
|
||||||
|
this.a(IChatMutableComponent.a(new LiteralContents(ticks + "")));
|
||||||
|
}
|
||||||
|
if (!this.exploded && exploded) {
|
||||||
|
this.n(true);
|
||||||
|
this.a(IChatMutableComponent.a(new LiteralContents("Bumm")));
|
||||||
|
this.exploded = true;
|
||||||
|
if (referenceCounter.increment() > 0) {
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
}
|
||||||
|
} else if (referenceCounter.increment() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendEntity(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player, boolean force) {
|
||||||
|
if (!force && referenceCounter.decrement() > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
ag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
70
BauSystem_19/src/de/steamwar/bausystem/entities/WarpEntity19.java
Normale Datei
70
BauSystem_19/src/de/steamwar/bausystem/entities/WarpEntity19.java
Normale Datei
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.entities;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.warp.AbstractWarpEntity;
|
||||||
|
import de.steamwar.bausystem.shared.BaseArmorStand19;
|
||||||
|
import net.minecraft.network.chat.IChatMutableComponent;
|
||||||
|
import net.minecraft.network.chat.contents.LiteralContents;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class WarpEntity19 extends BaseArmorStand19 implements AbstractWarpEntity {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public WarpEntity19(World world, Vector position, String name) {
|
||||||
|
super(world, position);
|
||||||
|
this.j(true);
|
||||||
|
this.a(true);
|
||||||
|
this.name = name;
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void display(Player player) {
|
||||||
|
this.n(true);
|
||||||
|
this.a(IChatMutableComponent.a(new LiteralContents(name)));
|
||||||
|
sendEntity(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hide(Player player) {
|
||||||
|
|
||||||
|
this.position.setY(this.position.getY() - 1000);
|
||||||
|
this.e(this.position.getX(), this.position.getY(), this.position.getZ());
|
||||||
|
|
||||||
|
PacketPlayOutEntityTeleport entityTeleport = new PacketPlayOutEntityTeleport(this);
|
||||||
|
((CraftPlayer) player).getHandle().b.a(entityTeleport);
|
||||||
|
|
||||||
|
sendEntityDestroy(player);
|
||||||
|
ag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
62
BauSystem_19/src/de/steamwar/bausystem/shared/BaseArmorStand19.java
Normale Datei
62
BauSystem_19/src/de/steamwar/bausystem/shared/BaseArmorStand19.java
Normale Datei
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.shared;
|
||||||
|
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
|
||||||
|
import net.minecraft.server.network.PlayerConnection;
|
||||||
|
import net.minecraft.world.entity.EntityTypes;
|
||||||
|
import net.minecraft.world.entity.decoration.EntityArmorStand;
|
||||||
|
import net.minecraft.world.phys.Vec3D;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class BaseArmorStand19 extends EntityArmorStand implements AbstractEntity {
|
||||||
|
|
||||||
|
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||||
|
|
||||||
|
protected Vector position;
|
||||||
|
|
||||||
|
public BaseArmorStand19(World world, Vector position) {
|
||||||
|
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ());
|
||||||
|
|
||||||
|
this.position = position;
|
||||||
|
e(true);
|
||||||
|
S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntity(Player player) {
|
||||||
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), cp(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.c, 0, ZERO, 0.0);
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b;
|
||||||
|
playerConnection.a(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true);
|
||||||
|
playerConnection.a(packetPlayOutEntityMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntityDestroy(Player player) {
|
||||||
|
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(ae());
|
||||||
|
((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy);
|
||||||
|
}
|
||||||
|
}
|
94
BauSystem_19/src/de/steamwar/bausystem/shared/BaseEntity19.java
Normale Datei
94
BauSystem_19/src/de/steamwar/bausystem/shared/BaseEntity19.java
Normale Datei
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.shared;
|
||||||
|
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
|
||||||
|
import net.minecraft.server.network.PlayerConnection;
|
||||||
|
import net.minecraft.world.entity.EntityTypes;
|
||||||
|
import net.minecraft.world.entity.item.EntityFallingBlock;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.state.IBlockData;
|
||||||
|
import net.minecraft.world.phys.Vec3D;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
public class BaseEntity19 extends EntityFallingBlock implements AbstractEntity {
|
||||||
|
|
||||||
|
private static final Field ao;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
ao = EntityFallingBlock.class.getDeclaredField("ao");
|
||||||
|
ao.setAccessible(true);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||||
|
|
||||||
|
private final IBlockData iBlockData;
|
||||||
|
protected Vector position;
|
||||||
|
|
||||||
|
public BaseEntity19(World world, Vector position, Material blockType) {
|
||||||
|
super(EntityTypes.E, ((CraftWorld) world).getHandle());
|
||||||
|
try {
|
||||||
|
ao.set(this, ((CraftBlockData) blockType.createBlockData()).getState());
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
this.q = true;
|
||||||
|
e(position.getX(), position.getY(), position.getZ());
|
||||||
|
f(Vec3D.b);
|
||||||
|
t = position.getX();
|
||||||
|
u = position.getY();
|
||||||
|
v = position.getZ();
|
||||||
|
a(this.db());
|
||||||
|
|
||||||
|
this.iBlockData = ((CraftBlockData) blockType.createBlockData()).getState();
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
this.e(true);
|
||||||
|
this.S = -12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntity(Player player) {
|
||||||
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), cp(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.E, Block.i(iBlockData), ZERO, 0.0);
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b;
|
||||||
|
playerConnection.a(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true);
|
||||||
|
playerConnection.a(packetPlayOutEntityMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEntityDestroy(Player player) {
|
||||||
|
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(ae());
|
||||||
|
((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy);
|
||||||
|
}
|
||||||
|
}
|
@ -21,60 +21,81 @@ package de.steamwar.bausystem.utils;
|
|||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
|
import de.steamwar.bausystem.entities.DetonatorEntity19;
|
||||||
|
import de.steamwar.bausystem.entities.SimulatorEntity19;
|
||||||
|
import de.steamwar.bausystem.entities.TraceEntity19;
|
||||||
|
import de.steamwar.bausystem.entities.WarpEntity19;
|
||||||
|
import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity;
|
||||||
import de.steamwar.bausystem.features.util.NoClipCommand;
|
import de.steamwar.bausystem.features.util.NoClipCommand;
|
||||||
|
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
||||||
|
import de.steamwar.bausystem.features.tracer.AbstractTraceEntity;
|
||||||
|
import de.steamwar.bausystem.features.warp.AbstractWarpEntity;
|
||||||
import net.minecraft.SystemUtils;
|
import net.minecraft.SystemUtils;
|
||||||
import net.minecraft.nbt.NBTBase;
|
import net.minecraft.nbt.NBTBase;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||||
import net.minecraft.network.syncher.DataWatcher;
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange;
|
||||||
import net.minecraft.server.level.PlayerInteractManager;
|
import net.minecraft.server.level.PlayerInteractManager;
|
||||||
import net.minecraft.world.level.EnumGamemode;
|
import net.minecraft.world.level.EnumGamemode;
|
||||||
import net.minecraft.world.phys.Vec3D;
|
import net.minecraft.world.phys.Vec3D;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||||
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity;
|
|
||||||
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
|
|
||||||
import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.LongSupplier;
|
import java.util.function.LongSupplier;
|
||||||
|
|
||||||
public class NMSWrapper19 implements NMSWrapper {
|
public class NMSWrapper19 implements NMSWrapper.INMSWrapper {
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
|
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void setInternalGameMode(Player player, GameMode gameMode) {
|
public void setInternalGameMode(Player player, GameMode gameMode) {
|
||||||
playerGameMode.set(((CraftPlayer) player).getHandle().d, EnumGamemode.a(gameMode.getValue()));
|
playerGameMode.set(((CraftPlayer) player).getHandle().d, EnumGamemode.a(gameMode.getValue()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSlotToItemStack(Player player, Object o) {
|
public void init(LongSupplier longSupplier) {
|
||||||
PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot = (PacketPlayInSetCreativeSlot) o;
|
SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong();
|
||||||
int index = packetPlayInSetCreativeSlot.b();
|
|
||||||
if (index >= 36 && index <= 44) {
|
|
||||||
index -= 36;
|
|
||||||
} else if (index > 44) {
|
|
||||||
index -= 5;
|
|
||||||
} else if (index <= 8) {
|
|
||||||
index = index - 8 + 36;
|
|
||||||
}
|
}
|
||||||
player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.c()));
|
|
||||||
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
private static final List<Packet<?>> packets = new ArrayList<>();
|
||||||
player.updateInventory();
|
private static final Vec3D noMotion = new Vec3D(0, 0, 0);
|
||||||
|
@Override
|
||||||
|
public void createTickCache(World world) {
|
||||||
|
packets.clear();
|
||||||
|
world.getEntities().stream().filter(entity -> !(entity instanceof Player)).forEach(entity -> {
|
||||||
|
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
|
||||||
|
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
|
||||||
|
|
||||||
|
if (entity instanceof TNTPrimed) {
|
||||||
|
net.minecraft.world.entity.Entity serverEntity = ((CraftEntity) entity).getHandle();
|
||||||
|
packets.add(new PacketPlayOutEntityMetadata(serverEntity.ae(), serverEntity.ai(), true));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTickPackets() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
|
for (Packet<?> p : packets) {
|
||||||
|
TinyProtocol.instance.sendPacket(player, p);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
|
private static final Reflection.FieldAccessor<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGameStateChangeReason(Object packet) {
|
public void setGameStateChangeReason(Object packet) {
|
||||||
gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d);
|
gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d);
|
||||||
@ -82,8 +103,13 @@ public class NMSWrapper19 implements NMSWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPlayerBuildAbilities(Player player) {
|
public void setPlayerBuildAbilities(Player player) {
|
||||||
((CraftPlayer) player).getHandle().fF().d = true;
|
((CraftPlayer) player).getHandle().fC().d = true;
|
||||||
((CraftPlayer) player).getHandle().fF().e = true;
|
((CraftPlayer) player).getHandle().fC().e = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Particle tntPositionParticle() {
|
||||||
|
return Particle.BLOCK_MARKER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -92,7 +118,6 @@ public class NMSWrapper19 implements NMSWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final int threshold = 2048;
|
private static final int threshold = 2048;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkItemStack(ItemStack item) {
|
public boolean checkItemStack(ItemStack item) {
|
||||||
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||||
@ -130,16 +155,23 @@ public class NMSWrapper19 implements NMSWrapper {
|
|||||||
return invalid;
|
return invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion");
|
@Override
|
||||||
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0);
|
public AbstractWarpEntity createWarp(World world, Vector position, String name) {
|
||||||
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1);
|
return new WarpEntity19(world, position, name);
|
||||||
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2);
|
}
|
||||||
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0);
|
|
||||||
private final Reflection.FieldAccessor<List> e = Reflection.getField(explosionPacket, List.class, 0);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resetExplosionKnockback(Object packet) {
|
public AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight) {
|
||||||
PacketPlayOutExplosion packetPlayOutExplosion = (PacketPlayOutExplosion) packet;
|
return new SimulatorEntity19(world, tntPosition, highlight);
|
||||||
return new PacketPlayOutExplosion(a.get(packetPlayOutExplosion), b.get(packetPlayOutExplosion), c.get(packetPlayOutExplosion), d.get(packetPlayOutExplosion), e.get(packetPlayOutExplosion), null);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractDetonatorEntity constructDetonator(World world, Vector position) {
|
||||||
|
return new DetonatorEntity19(world, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt) {
|
||||||
|
return new TraceEntity19(world, tntPosition, tnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
|
||||||
import net.minecraft.network.protocol.game.PacketPlayInFlying;
|
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class PlayerMovementWrapper19 implements PlayerMovementWrapper {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPosition(Player player, Object object) {
|
|
||||||
PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object);
|
|
||||||
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
|
|
||||||
if (packetPlayInFlying.h) {
|
|
||||||
entityPlayer.b(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c, packetPlayInFlying.d, packetPlayInFlying.e);
|
|
||||||
} else {
|
|
||||||
entityPlayer.e(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convertToOut(Player player, Object object) {
|
|
||||||
PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object);
|
|
||||||
Object packet = Reflection.newInstance(teleportPacket);
|
|
||||||
teleportEntity.set(packet, player.getEntityId());
|
|
||||||
teleportPosition.set(packet, packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c);
|
|
||||||
if (packetPlayInFlying.h) {
|
|
||||||
teleportYaw.set(packet, rotToByte(player.getLocation().getYaw()));
|
|
||||||
teleportPitch.set(packet, rotToByte(player.getLocation().getPitch()));
|
|
||||||
} else {
|
|
||||||
teleportYaw.set(packet, rotToByte(packetPlayInFlying.d));
|
|
||||||
teleportPitch.set(packet, rotToByte(packetPlayInFlying.e));
|
|
||||||
}
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
}
|
|
33
BauSystem_19/src/de/steamwar/bausystem/utils/ProtocolWrapper19.java
Normale Datei
33
BauSystem_19/src/de/steamwar/bausystem/utils/ProtocolWrapper19.java
Normale Datei
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.utils;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import de.steamwar.bausystem.features.util.NoClipCommand;
|
||||||
|
|
||||||
|
public class ProtocolWrapper19 implements ProtocolWrapper {
|
||||||
|
|
||||||
|
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(NoClipCommand.playerInfoDataClass, GameProfile.class, int.class, NoClipCommand.enumGamemode, NoClipCommand.iChatBaseComponent, Reflection.getClass("net.minecraft.world.entity.player.ProfilePublicKey$a"));
|
||||||
|
@Override
|
||||||
|
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) {
|
||||||
|
return playerInfoDataConstructor.invoke(profile, 0, mode, null, null);
|
||||||
|
}
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
|
||||||
|
|
||||||
import com.destroystokyo.paper.event.server.ServerTickEndEvent;
|
|
||||||
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
public class TickListener19 implements TickListener, Listener {
|
|
||||||
|
|
||||||
private boolean tickStartRan = false;
|
|
||||||
|
|
||||||
public TickListener19() {
|
|
||||||
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServerTickStart(ServerTickStartEvent event) {
|
|
||||||
if (TPSFreezeUtils.isFrozen()) return;
|
|
||||||
Bukkit.getPluginManager().callEvent(new TickStartEvent());
|
|
||||||
tickStartRan = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServerTickEnd(ServerTickEndEvent event) {
|
|
||||||
if (!tickStartRan) return;
|
|
||||||
Bukkit.getPluginManager().callEvent(new TickEndEvent());
|
|
||||||
tickStartRan = false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id 'base'
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
group 'steamwar'
|
|
||||||
version '1.0'
|
|
||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
|
||||||
|
|
||||||
sourceCompatibility = 17
|
|
||||||
targetCompatibility = 17
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
java {
|
|
||||||
srcDirs = ['src/']
|
|
||||||
}
|
|
||||||
resources {
|
|
||||||
srcDirs = ['src/']
|
|
||||||
exclude '**/*.java', '**/*.kt'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.22'
|
|
||||||
testCompileOnly 'org.projectlombok:lombok:1.18.22'
|
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
|
||||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
|
|
||||||
|
|
||||||
implementation project(":BauSystem_Main")
|
|
||||||
|
|
||||||
compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT'
|
|
||||||
compileOnly 'it.unimi.dsi:fastutil:8.5.6'
|
|
||||||
compileOnly 'com.mojang:datafixerupper:4.0.26'
|
|
||||||
compileOnly 'io.netty:netty-all:4.1.68.Final'
|
|
||||||
compileOnly 'com.mojang:authlib:1.5.25'
|
|
||||||
compileOnly 'com.mojang:brigadier:1.0.18'
|
|
||||||
|
|
||||||
compileOnly swdep('Spigot-1.20')
|
|
||||||
compileOnly swdep('SpigotCore')
|
|
||||||
}
|
|
@ -1,136 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
|
||||||
import de.steamwar.bausystem.features.util.NoClipCommand;
|
|
||||||
import net.minecraft.nbt.NBTBase;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot;
|
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutExplosion;
|
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange;
|
|
||||||
import net.minecraft.server.level.PlayerInteractManager;
|
|
||||||
import net.minecraft.world.level.EnumGamemode;
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class NMSWrapper20 implements NMSWrapper {
|
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<EnumGamemode> playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public void setInternalGameMode(Player player, GameMode gameMode) {
|
|
||||||
playerGameMode.set(((CraftPlayer) player).getHandle().e, EnumGamemode.a(gameMode.getValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSlotToItemStack(Player player, Object o) {
|
|
||||||
PacketPlayInSetCreativeSlot packetPlayInSetCreativeSlot = (PacketPlayInSetCreativeSlot) o;
|
|
||||||
int index = packetPlayInSetCreativeSlot.a();
|
|
||||||
if (index >= 36 && index <= 44) {
|
|
||||||
index -= 36;
|
|
||||||
} else if (index > 44) {
|
|
||||||
index -= 5;
|
|
||||||
} else if (index <= 8) {
|
|
||||||
index = index - 8 + 36;
|
|
||||||
}
|
|
||||||
player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(packetPlayInSetCreativeSlot.c()));
|
|
||||||
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
|
||||||
player.updateInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Reflection.FieldAccessor<PacketPlayOutGameStateChange.a> gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setGameStateChangeReason(Object packet) {
|
|
||||||
gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPlayerBuildAbilities(Player player) {
|
|
||||||
((CraftPlayer) player).getHandle().fO().d = true;
|
|
||||||
((CraftPlayer) player).getHandle().fO().e = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Material pathMaterial() {
|
|
||||||
return Material.DIRT_PATH;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int threshold = 2048;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkItemStack(ItemStack item) {
|
|
||||||
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
|
||||||
NBTTagCompound tag = nmsItem.v();
|
|
||||||
if (tag != null && tag.e("BlockEntityTag")) {
|
|
||||||
NBTTagCompound blockTag = tag.p("BlockEntityTag");
|
|
||||||
if (blockTag.e("Items")) {
|
|
||||||
return drillDown(blockTag.c("Items", 10), 0, 0) > threshold;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int drillDown(NBTTagList items, int layer, int start) {
|
|
||||||
if (layer > 2) return start + threshold;
|
|
||||||
int invalid = start;
|
|
||||||
for (NBTBase nbtBase : items) {
|
|
||||||
if (!(nbtBase instanceof NBTTagCompound))
|
|
||||||
continue;
|
|
||||||
NBTTagCompound slot = (NBTTagCompound) nbtBase;
|
|
||||||
if (slot.e("tag")) {
|
|
||||||
invalid += slot.f("Count");
|
|
||||||
NBTTagCompound iTag = slot.p("tag");
|
|
||||||
if (iTag.e("BlockEntityTag")) {
|
|
||||||
NBTTagCompound blockTag = iTag.p("BlockEntityTag");
|
|
||||||
if (blockTag.e("Items")) {
|
|
||||||
invalid = drillDown(blockTag.c("Items", 10), layer + 1, invalid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (invalid > threshold)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion");
|
|
||||||
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0);
|
|
||||||
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1);
|
|
||||||
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2);
|
|
||||||
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0);
|
|
||||||
private final Reflection.FieldAccessor<List> e = Reflection.getField(explosionPacket, List.class, 0);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object resetExplosionKnockback(Object packet) {
|
|
||||||
PacketPlayOutExplosion packetPlayOutExplosion = (PacketPlayOutExplosion) packet;
|
|
||||||
return new PacketPlayOutExplosion(a.get(packetPlayOutExplosion), b.get(packetPlayOutExplosion), c.get(packetPlayOutExplosion), d.get(packetPlayOutExplosion), e.get(packetPlayOutExplosion), null);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
|
|
||||||
public class PlaceItemWrapper20 implements PlaceItemWrapper {
|
|
||||||
|
|
||||||
public PlaceItemWrapper20() {
|
|
||||||
for (Material material : Material.values()) {
|
|
||||||
if (!material.isBlock()) continue;
|
|
||||||
if (material.isLegacy()) continue;
|
|
||||||
BlockData blockData = material.createBlockData();
|
|
||||||
Material placementMaterial = blockData.getPlacementMaterial();
|
|
||||||
if (material == placementMaterial) continue;
|
|
||||||
if (placementMaterial == Material.AIR) continue;
|
|
||||||
if (placementMaterial.isItem() && !placementMaterial.isBlock()) {
|
|
||||||
ITEM_MATERIAL_TO_BLOCK_MATERIAL.put(placementMaterial, material);
|
|
||||||
}
|
|
||||||
if (material.name().contains("WALL")) {
|
|
||||||
BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.put(placementMaterial, material);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.utils;
|
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
|
||||||
import net.minecraft.network.protocol.game.PacketPlayInFlying;
|
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport;
|
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class PlayerMovementWrapper20 implements PlayerMovementWrapper {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPosition(Player player, Object object) {
|
|
||||||
PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object);
|
|
||||||
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
|
|
||||||
if (packetPlayInFlying.h) {
|
|
||||||
entityPlayer.b(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c, packetPlayInFlying.d, packetPlayInFlying.e);
|
|
||||||
} else {
|
|
||||||
entityPlayer.e(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convertToOut(Player player, Object object) {
|
|
||||||
PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object);
|
|
||||||
Object packet = Reflection.newInstance(teleportPacket);
|
|
||||||
teleportEntity.set(packet, player.getEntityId());
|
|
||||||
teleportPosition.set(packet, packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c);
|
|
||||||
if (packetPlayInFlying.h) {
|
|
||||||
teleportYaw.set(packet, rotToByte(player.getLocation().getYaw()));
|
|
||||||
teleportPitch.set(packet, rotToByte(player.getLocation().getPitch()));
|
|
||||||
} else {
|
|
||||||
teleportYaw.set(packet, rotToByte(packetPlayInFlying.d));
|
|
||||||
teleportPitch.set(packet, rotToByte(packetPlayInFlying.e));
|
|
||||||
}
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.linkage.types;
|
|
||||||
|
|
||||||
import de.steamwar.linkage.LinkageType;
|
|
||||||
import de.steamwar.linkage.plan.BuildPlan;
|
|
||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
|
||||||
|
|
||||||
import javax.lang.model.element.TypeElement;
|
|
||||||
|
|
||||||
public class BauGuiItem_GENERIC implements LinkageType {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String method() {
|
|
||||||
return "linkGUIItems";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
|
|
||||||
buildPlan.addImport("de.steamwar.bausystem.features.gui.BauGUI");
|
|
||||||
methodBuilder.addLine("BauGUI.addItem(" + s + ");");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.linkage.types;
|
|
||||||
|
|
||||||
import de.steamwar.linkage.LinkageType;
|
|
||||||
import de.steamwar.linkage.plan.BuildPlan;
|
|
||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
|
||||||
|
|
||||||
import javax.lang.model.element.TypeElement;
|
|
||||||
|
|
||||||
public class BoundingBoxLoader_GENERIC implements LinkageType {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String method() {
|
|
||||||
return "linkBoundingBox";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
|
|
||||||
method.addLine(instance + ".load();");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.linkage.types;
|
|
||||||
|
|
||||||
import de.steamwar.linkage.LinkageType;
|
|
||||||
import de.steamwar.linkage.plan.BuildPlan;
|
|
||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
|
||||||
|
|
||||||
import javax.lang.model.element.TypeElement;
|
|
||||||
|
|
||||||
public class FAWEPatternParser_GENERIC implements LinkageType {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String method() {
|
|
||||||
return "link";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
|
|
||||||
methodBuilder.addLine("if (org.bukkit.Bukkit.getPluginManager().getPlugin(\"FastAsyncWorldEdit\") != null) {");
|
|
||||||
methodBuilder.addLine(" " + s + ";");
|
|
||||||
methodBuilder.addLine("}");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.linkage.types;
|
|
||||||
|
|
||||||
import de.steamwar.linkage.LinkageType;
|
|
||||||
import de.steamwar.linkage.plan.BuildPlan;
|
|
||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
|
||||||
|
|
||||||
import javax.lang.model.element.TypeElement;
|
|
||||||
|
|
||||||
public class LuaLib_GENERIC implements LinkageType {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String method() {
|
|
||||||
return "link";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
|
|
||||||
buildPlan.addImport("de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin");
|
|
||||||
methodBuilder.addLine("SteamWarLuaPlugin.add(" + s + ");");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.linkage.types;
|
|
||||||
|
|
||||||
import de.steamwar.linkage.LinkageType;
|
|
||||||
import de.steamwar.linkage.plan.BuildPlan;
|
|
||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
|
||||||
|
|
||||||
import javax.lang.model.element.TypeElement;
|
|
||||||
|
|
||||||
public class PanzernAlgorithm_GENERIC implements LinkageType {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String method() {
|
|
||||||
return "linkPanzern";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
|
|
||||||
buildPlan.addImport("de.steamwar.bausystem.features.slaves.panzern.Panzern");
|
|
||||||
methodBuilder.addLine("Panzern.add(" + s + ");");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.linkage.types;
|
|
||||||
|
|
||||||
import de.steamwar.linkage.LinkageType;
|
|
||||||
import de.steamwar.linkage.plan.BuildPlan;
|
|
||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
|
||||||
|
|
||||||
import javax.lang.model.element.TypeElement;
|
|
||||||
|
|
||||||
public class ScoreboardElement_GENERIC implements LinkageType {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String method() {
|
|
||||||
return "link";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) {
|
|
||||||
buildPlan.addImport("de.steamwar.bausystem.features.world.BauScoreboard");
|
|
||||||
methodBuilder.addLine("BauScoreboard.addElement(" + s + ");");
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,13 +27,13 @@ version '1.0'
|
|||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
sourceCompatibility = 17
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 17
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
java {
|
java {
|
||||||
srcDirs = ['src/', 'build/generated/sources/annotationProcessor/java/main/']
|
srcDirs = ['src/']
|
||||||
}
|
}
|
||||||
resources {
|
resources {
|
||||||
srcDirs = ['src/']
|
srcDirs = ['src/']
|
||||||
@ -51,19 +51,16 @@ dependencies {
|
|||||||
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
||||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
|
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
|
||||||
|
|
||||||
implementation project(":BauSystem_Linkage")
|
implementation 'org.atteo.classindex:classindex:3.11'
|
||||||
annotationProcessor project(":BauSystem_Linkage")
|
testImplementation 'org.atteo.classindex:classindex:3.11'
|
||||||
|
annotationProcessor 'org.atteo.classindex:classindex:3.11'
|
||||||
|
testAnnotationProcessor 'org.atteo.classindex:classindex:3.11'
|
||||||
|
|
||||||
compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT'
|
compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
|
||||||
compileOnly 'com.mojang:authlib:1.5.25'
|
compileOnly 'com.mojang:authlib:1.5.25'
|
||||||
compileOnly 'io.netty:netty-all:4.1.68.Final'
|
compileOnly 'io.netty:netty-all:4.1.68.Final'
|
||||||
|
|
||||||
compileOnly swdep('Spigot-1.20')
|
compileOnly swdep('Spigot-1.19')
|
||||||
|
compileOnly swdep('WorldEdit-1.15')
|
||||||
compileOnly swdep('SpigotCore')
|
compileOnly swdep('SpigotCore')
|
||||||
annotationProcessor swdep('SpigotCore')
|
|
||||||
|
|
||||||
compileOnly swdep('FastAsyncWorldEdit-1.18')
|
|
||||||
compileOnly swdep('AxiomPaper')
|
|
||||||
|
|
||||||
implementation 'org.luaj:luaj-jse:3.0.1'
|
|
||||||
}
|
}
|
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
@ -21,44 +21,45 @@ package de.steamwar.bausystem;
|
|||||||
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils;
|
|
||||||
import de.steamwar.bausystem.linkage.LinkageUtils;
|
import de.steamwar.bausystem.linkage.LinkageUtils;
|
||||||
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
||||||
import de.steamwar.bausystem.region.loader.RegionLoader;
|
import de.steamwar.bausystem.region.loader.RegionLoader;
|
||||||
import de.steamwar.bausystem.region.loader.Updater;
|
import de.steamwar.bausystem.region.loader.Updater;
|
||||||
import de.steamwar.bausystem.utils.TickListener;
|
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
import de.steamwar.bausystem.worlddata.WorldData;
|
||||||
import de.steamwar.command.AbstractValidator;
|
|
||||||
import de.steamwar.command.SWCommandUtils;
|
|
||||||
import de.steamwar.message.Message;
|
import de.steamwar.message.Message;
|
||||||
|
import de.steamwar.scoreboard.SWScoreboard;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.nio.file.Files;
|
||||||
import java.util.function.Consumer;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.nio.file.attribute.FileTime;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class BauSystem extends JavaPlugin implements Listener {
|
public class BauSystem extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
// This should be treated as final!
|
// This should be treated as final!
|
||||||
public static Message MESSAGE;
|
public static Message MESSAGE;
|
||||||
public static final boolean DEV_SERVER = !System.getProperty("user.home").endsWith("minecraft");
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static BauSystem instance;
|
private static BauSystem instance;
|
||||||
|
|
||||||
|
private World world;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
SWScoreboard.class.getName();
|
||||||
|
world = Bukkit.getWorlds().get(0);
|
||||||
|
fixBauSystem();
|
||||||
|
|
||||||
// LOGGER
|
// LOGGER
|
||||||
fixLogging();
|
fixLogging();
|
||||||
|
|
||||||
@ -73,40 +74,13 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||||
Bukkit.shutdown();
|
Bukkit.shutdown();
|
||||||
System.exit(1);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Updater(PrototypeLoader.file, PrototypeLoader::load);
|
new Updater(PrototypeLoader.file, PrototypeLoader::load);
|
||||||
new Updater(RegionLoader.file, RegionLoader::load);
|
new Updater(RegionLoader.file, RegionLoader::load);
|
||||||
|
|
||||||
SWCommandUtils.addValidator(Player.class, validator(Permission.BUILD));
|
|
||||||
SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD));
|
|
||||||
SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR));
|
|
||||||
SWCommandUtils.addValidator("owner", validator(Permission.OWNER));
|
|
||||||
|
|
||||||
try {
|
|
||||||
LinkageUtils.link();
|
LinkageUtils.link();
|
||||||
} catch (Exception e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
|
||||||
Bukkit.shutdown();
|
|
||||||
System.exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TickListener.impl.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T extends CommandSender> AbstractValidator<T, ?> validator(Permission permission) {
|
|
||||||
return (commandSender, object, messageSender) -> {
|
|
||||||
if (commandSender instanceof Player) {
|
|
||||||
if (permission.hasPermission((Player) commandSender)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
messageSender.send("NO_PERMISSION");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -139,44 +113,59 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BukkitTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
|
private void fixBauSystem() {
|
||||||
return new BukkitRunnable() {
|
if (!new File(world.getWorldFolder(), "sections.yml").exists()) {
|
||||||
private int counter = 1;
|
try {
|
||||||
|
Path path = new File(world.getWorldFolder(), "region").toPath();
|
||||||
@Override
|
BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class);
|
||||||
public void run() {
|
FileTime creationTime = attributes.creationTime();
|
||||||
if (TPSFreezeUtils.isFrozen()) return;
|
long millis = creationTime.toMillis();
|
||||||
if (counter >= delay) {
|
if (millis < 1611081960) {
|
||||||
runnable.run();
|
createLink("sections3.yml", "sections.yml");
|
||||||
cancel();
|
} else {
|
||||||
|
createLink("sections4.yml", "sections.yml");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||||
|
Bukkit.shutdown();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
}.runTaskTimer(plugin, 0, 1);
|
int number = -1;
|
||||||
}
|
try {
|
||||||
|
String string = new File(world.getWorldFolder(), "sections.yml").getCanonicalPath();
|
||||||
public static BukkitTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
|
if (string.endsWith("/sections2.yml")) number = 2;
|
||||||
return new BukkitRunnable() {
|
if (string.endsWith("/sections3.yml")) number = 3;
|
||||||
private int counter = 1;
|
if (string.endsWith("/sections4.yml")) number = 4;
|
||||||
private boolean first = true;
|
Bukkit.getLogger().log(Level.INFO, "SectionFile: " + string);
|
||||||
|
} catch (IOException e) {
|
||||||
@Override
|
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||||
public void run() {
|
Bukkit.shutdown();
|
||||||
if (TPSFreezeUtils.isFrozen()) return;
|
|
||||||
if (counter >= (first ? delay : period)) {
|
|
||||||
first = false;
|
|
||||||
runnable.run();
|
|
||||||
counter = 1;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
counter++;
|
if (number == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!new File(world.getWorldFolder(),"prototypes.yapion").exists()) {
|
||||||
|
createLink("prototypes" + number + ".yapion", "prototypes.yapion");
|
||||||
|
}
|
||||||
|
if (!new File(world.getWorldFolder(),"regions.yapion").exists()) {
|
||||||
|
createLink("regions" + number + ".yapion", "regions.yapion");
|
||||||
}
|
}
|
||||||
}.runTaskTimer(plugin, 0, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runTaskTimer(Plugin plugin, Consumer<BukkitTask> consumer, long delay, long period) {
|
private void createLink(String source, String destination) {
|
||||||
AtomicReference<BukkitTask> task = new AtomicReference<>();
|
try {
|
||||||
task.set(runTaskTimer(plugin, () -> consumer.accept(task.get()), delay, period));
|
Bukkit.getLogger().log(Level.INFO, "Executing: ln -s /home/minecraft/server/Bau15/{0} {1}", new String[]{source, destination});
|
||||||
|
ProcessBuilder processBuilder = new ProcessBuilder("ln", "-s", "/home/minecraft/server/Bau15/" + source, destination);
|
||||||
|
processBuilder.directory(world.getWorldFolder());
|
||||||
|
processBuilder.inheritIO();
|
||||||
|
|
||||||
|
Process process = processBuilder.start();
|
||||||
|
process.waitFor();
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
Bukkit.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,77 +20,54 @@
|
|||||||
package de.steamwar.bausystem;
|
package de.steamwar.bausystem;
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.BauServer;
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
import de.steamwar.bausystem.features.world.BauMemberUpdate;
|
|
||||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
|
||||||
import de.steamwar.sql.BauweltMember;
|
import de.steamwar.sql.BauweltMember;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum Permission {
|
public enum Permission {
|
||||||
|
|
||||||
OWNER(bauweltMember -> false),
|
WORLD(BauweltMember::isWorld),
|
||||||
SUPERVISOR(bauweltMember -> {
|
WORLDEDIT(BauweltMember::isWorldEdit),
|
||||||
return bauweltMember.isSupervisor();
|
MEMBER(bauweltMember -> true),
|
||||||
}),
|
OWNER(bauweltMember -> false);
|
||||||
BUILD(bauweltMember -> {
|
|
||||||
if (isTempOnlySpectator(bauweltMember)) return false;
|
|
||||||
return bauweltMember.isBuild() || SUPERVISOR.permissionPredicate.test(bauweltMember);
|
|
||||||
}),
|
|
||||||
/**
|
|
||||||
* Only used for {@link BauMemberUpdate}
|
|
||||||
*/
|
|
||||||
REAL_SPECTATOR(bauweltMember -> {
|
|
||||||
return !bauweltMember.isBuild() && !bauweltMember.isSupervisor();
|
|
||||||
}),
|
|
||||||
/**
|
|
||||||
* Primarily used for {@link de.steamwar.bausystem.linkage.specific.GuiItem}
|
|
||||||
*/
|
|
||||||
MEMBER(bauweltMember -> {
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
private static final Set<Integer> TEMP_ONLY_SPECTATOR = new HashSet<>();
|
|
||||||
|
|
||||||
private static boolean isTempOnlySpectator(BauweltMember bauweltMember) {
|
|
||||||
return TEMP_ONLY_SPECTATOR.contains(bauweltMember.getMemberID());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isTempOnlySpectator(Player player) {
|
|
||||||
return TEMP_ONLY_SPECTATOR.contains(SteamwarUser.get(player.getUniqueId()).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void forceOnlySpectator(Player player) {
|
|
||||||
TEMP_ONLY_SPECTATOR.add(SteamwarUser.get(player.getUniqueId()).getId());
|
|
||||||
BauMemberUpdate.baumemberUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only used by {@link BauMemberUpdate}
|
|
||||||
*/
|
|
||||||
public static void removeForceOnlySpectator(Player player) {
|
|
||||||
TEMP_ONLY_SPECTATOR.remove(SteamwarUser.get(player.getUniqueId()).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Predicate<BauweltMember> permissionPredicate;
|
private final Predicate<BauweltMember> permissionPredicate;
|
||||||
|
|
||||||
public boolean hasPermission(BauweltMember bauweltMember) {
|
public boolean hasPermission(Player member) {
|
||||||
if (bauweltMember == null) return false;
|
if (member.getUniqueId().equals(BauServer.getInstance().getOwner())) {
|
||||||
return permissionPredicate.test(bauweltMember);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPermission(Player member) {
|
BauweltMember bauMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId());
|
||||||
if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) {
|
if (bauMember == null) {
|
||||||
return this != REAL_SPECTATOR;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return permissionPredicate.test(bauMember);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasPermission(Player member, Permission permission) {
|
||||||
|
return permission.hasPermission(member);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendMessages(Player player, boolean ableTo, BauweltMember target, String what) {
|
||||||
|
Player targetPlayer = Bukkit.getPlayer(SteamwarUser.get(target.getMemberID()).getUUID());
|
||||||
|
if (targetPlayer != null) {
|
||||||
|
if (ableTo) {
|
||||||
|
BauSystem.MESSAGE.send("PERMISSION_CHANGE_OTHER_ENABLE", targetPlayer, player.getName(), BauSystem.MESSAGE.parse(what, targetPlayer));
|
||||||
|
} else {
|
||||||
|
BauSystem.MESSAGE.send("PERMISSION_CHANGE_OTHER_DISABLE", targetPlayer, player.getName(), BauSystem.MESSAGE.parse(what, targetPlayer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ableTo) {
|
||||||
|
BauSystem.MESSAGE.send("PERMISSION_CHANGE_YOU_ENABLE", player, BauSystem.MESSAGE.parse(what, player));
|
||||||
|
} else {
|
||||||
|
BauSystem.MESSAGE.send("PERMISSION_CHANGE_YOU_DISABLE", player, BauSystem.MESSAGE.parse(what, player));
|
||||||
}
|
}
|
||||||
BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId());
|
|
||||||
if (bauweltMember == null) return this == REAL_SPECTATOR;
|
|
||||||
return permissionPredicate.test(bauweltMember);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem;
|
package de.steamwar.bausystem;
|
||||||
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
@ -30,7 +29,6 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -61,13 +59,6 @@ public class SWUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SWItem setCustomModelData(SWItem item, int customModelData) {
|
|
||||||
ItemMeta itemMeta = item.getItemMeta();
|
|
||||||
itemMeta.setCustomModelData(customModelData);
|
|
||||||
item.setItemMeta(itemMeta);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendToActionbar(Player p, String message) {
|
public static void sendToActionbar(Player p, String message) {
|
||||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
|
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.config;
|
package de.steamwar.bausystem.config;
|
||||||
|
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.providers.BauServerInfo;
|
import de.steamwar.providers.BauServerInfo;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.PLAIN)
|
||||||
public class BauServer {
|
public class BauServer {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
package de.steamwar.bausystem.configplayer;
|
package de.steamwar.bausystem.configplayer;
|
||||||
|
|
||||||
import de.steamwar.bausystem.configplayer.serializer.ConfigurationSerializableSerializer;
|
import de.steamwar.bausystem.configplayer.serializer.ConfigurationSerializableSerializer;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.sql.UserConfig;
|
import de.steamwar.sql.UserConfig;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -39,7 +40,7 @@ import java.util.Map;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.LISTENER)
|
||||||
public class Config implements Listener {
|
public class Config implements Listener {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -97,7 +98,7 @@ public class Config implements Listener {
|
|||||||
|
|
||||||
public void saveAll() {
|
public void saveAll() {
|
||||||
playerConfigurations.forEach((uuid, yapionObject) -> {
|
playerConfigurations.forEach((uuid, yapionObject) -> {
|
||||||
String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\+", "\\");
|
String string = yapionObject.toYAPION(new StringOutput()).getResult();
|
||||||
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
||||||
});
|
});
|
||||||
playerConfigurations.clear();
|
playerConfigurations.clear();
|
||||||
@ -112,7 +113,7 @@ public class Config implements Listener {
|
|||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
if (playerConfigurations.containsKey(uuid)) {
|
if (playerConfigurations.containsKey(uuid)) {
|
||||||
YAPIONObject yapionObject = playerConfigurations.get(uuid);
|
YAPIONObject yapionObject = playerConfigurations.get(uuid);
|
||||||
String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\\\+", "\\\\");
|
String string = yapionObject.toYAPION(new StringOutput()).getResult();
|
||||||
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,112 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.attributescopy;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.command.PreviousArguments;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.linkage.MinVersion;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class AttributeRemoveCommand extends SWCommand {
|
|
||||||
|
|
||||||
public AttributeRemoveCommand() {
|
|
||||||
super("removeattribute", "attributesremove");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register({"all"})
|
|
||||||
@Register({"*"})
|
|
||||||
public void genericCommand(@Validator Player player) {
|
|
||||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
itemMeta.setLore(new ArrayList<>());
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
|
||||||
BauSystem.MESSAGE.send("ATTRIBUTE_REMOVE_ALL", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(description = "ATTRIBUTE_REMOVE_COMMAND_HELP")
|
|
||||||
public void genericCommand(@Validator Player player, @Mapper("attribute") String attribute) {
|
|
||||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
if (itemMeta == null) {
|
|
||||||
BauSystem.MESSAGE.send("ATTRIBUTE_REMOVE_NOT_FOUND", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<String> lore = itemMeta.getLore();
|
|
||||||
if (lore == null) {
|
|
||||||
BauSystem.MESSAGE.send("ATTRIBUTE_REMOVE_NOT_FOUND", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (lore.isEmpty()) {
|
|
||||||
BauSystem.MESSAGE.send("ATTRIBUTE_REMOVE_NOT_FOUND", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!lore.get(0).equals("§eAttributes§8:")) {
|
|
||||||
BauSystem.MESSAGE.send("ATTRIBUTE_REMOVE_NOT_FOUND", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lore.removeIf(s -> s.startsWith("§8-§7 " + attribute + "§8:"));
|
|
||||||
if (lore.size() == 1) {
|
|
||||||
itemStack.setItemMeta(null);
|
|
||||||
} else {
|
|
||||||
itemMeta.setLore(lore);
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
|
||||||
}
|
|
||||||
BauSystem.MESSAGE.send("ATTRIBUTE_REMOVE_SINGLE", player, attribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mapper(value = "attribute", local = true)
|
|
||||||
public TypeMapper<String> attribute() {
|
|
||||||
return new TypeMapper<String>() {
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
|
||||||
Player player = (Player) commandSender;
|
|
||||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
if (itemMeta == null) return null;
|
|
||||||
List<String> lore = itemMeta.getLore();
|
|
||||||
if (lore == null) return null;
|
|
||||||
if (lore.isEmpty()) return null;
|
|
||||||
if (!lore.get(0).equals("§eAttributes§8:")) return null;
|
|
||||||
return lore.stream()
|
|
||||||
.skip(1)
|
|
||||||
.map(s1 -> s1.substring(6))
|
|
||||||
.map(s1 -> s1.substring(0, s1.indexOf("§8:")))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,128 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.attributescopy;
|
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class AttributeUtils {
|
|
||||||
|
|
||||||
private Map<Method, String> names = new HashMap<>();
|
|
||||||
private Map<Class<?>, List<Method>> getters = new HashMap<>();
|
|
||||||
private Map<Class<?>, Map<String, Method>> setters = new HashMap<>();
|
|
||||||
|
|
||||||
private void generate(BlockData blockData) {
|
|
||||||
Class<? extends BlockData> clazz = blockData.getClass();
|
|
||||||
if (getters.containsKey(clazz) && setters.containsKey(clazz)) return;
|
|
||||||
|
|
||||||
Map<String, List<Method>> methods = new HashMap<>();
|
|
||||||
for (Method declaredMethod : clazz.getMethods()) {
|
|
||||||
String s = declaredMethod.getName();
|
|
||||||
if (s.startsWith("get") && declaredMethod.getParameterCount() == 0) {
|
|
||||||
methods.computeIfAbsent(s.substring(3), aClass -> new ArrayList<>()).add(declaredMethod);
|
|
||||||
} else if (s.startsWith("is") && declaredMethod.getParameterCount() == 0) {
|
|
||||||
methods.computeIfAbsent(s.substring(2), aClass -> new ArrayList<>()).add(declaredMethod);
|
|
||||||
} else if (s.startsWith("set") && declaredMethod.getParameterCount() == 1) {
|
|
||||||
methods.computeIfAbsent(s.substring(3), aClass -> new ArrayList<>()).add(declaredMethod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, List<Method>> entry : methods.entrySet()) {
|
|
||||||
if (entry.getValue().size() != 2) continue;
|
|
||||||
for (Method method : entry.getValue()) {
|
|
||||||
names.put(method, entry.getKey());
|
|
||||||
if (method.getName().startsWith("is") || method.getName().startsWith("get")) {
|
|
||||||
getters.computeIfAbsent(clazz, aClass -> new ArrayList<>()).add(method);
|
|
||||||
} else {
|
|
||||||
setters.computeIfAbsent(clazz, aClass -> new HashMap<>()).put(entry.getKey(), method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copy(BlockData blockData, List<String> attributes) {
|
|
||||||
generate(blockData);
|
|
||||||
|
|
||||||
getters.getOrDefault(blockData.getClass(), new ArrayList<>()).forEach(method -> {
|
|
||||||
try {
|
|
||||||
Object invoke = method.invoke(blockData);
|
|
||||||
if (invoke != null) {
|
|
||||||
attributes.add("§8-§7 " + names.get(method) + "§8:§7 " + convert(invoke));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void paste(BlockData blockData, List<String> attributes) {
|
|
||||||
generate(blockData);
|
|
||||||
|
|
||||||
for (String attribute : attributes) {
|
|
||||||
String[] split = attribute.split("§8:§7 ");
|
|
||||||
if (split.length != 2) continue;
|
|
||||||
String name = split[0].substring(6);
|
|
||||||
String value = split[1];
|
|
||||||
Method method = setters.getOrDefault(blockData.getClass(), new HashMap<>()).get(name);
|
|
||||||
if (method == null) continue;
|
|
||||||
try {
|
|
||||||
method.invoke(blockData, convert(value, method.getParameterTypes()[0]));
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String convert(Object o) {
|
|
||||||
if (o.getClass().isEnum()) {
|
|
||||||
return ((Enum<?>) o).name();
|
|
||||||
} else {
|
|
||||||
return o.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object convert(String s, Class<?> type) {
|
|
||||||
if (type.isEnum()) {
|
|
||||||
return Enum.valueOf((Class<? extends Enum>) type, s);
|
|
||||||
} else if (type == int.class || type == Integer.class) {
|
|
||||||
return Integer.parseInt(s);
|
|
||||||
} else if (type == double.class || type == Double.class) {
|
|
||||||
return Double.parseDouble(s);
|
|
||||||
} else if (type == float.class || type == Float.class) {
|
|
||||||
return Float.parseFloat(s);
|
|
||||||
} else if (type == long.class || type == Long.class) {
|
|
||||||
return Long.parseLong(s);
|
|
||||||
} else if (type == short.class || type == Short.class) {
|
|
||||||
return Short.parseShort(s);
|
|
||||||
} else if (type == byte.class || type == Byte.class) {
|
|
||||||
return Byte.parseByte(s);
|
|
||||||
} else if (type == boolean.class || type == Boolean.class) {
|
|
||||||
return Boolean.parseBoolean(s);
|
|
||||||
} else {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.attributescopy;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.FluidCollisionMode;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class AttributesCopyCommand extends SWCommand {
|
|
||||||
|
|
||||||
public AttributesCopyCommand() {
|
|
||||||
super("copyattributes", "attributescopy", "ac");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(@Validator Player player) {
|
|
||||||
Block block = player.getTargetBlockExact(8, FluidCollisionMode.ALWAYS);
|
|
||||||
if (block == null) return;
|
|
||||||
ItemStack mainHand = player.getInventory().getItemInMainHand();
|
|
||||||
|
|
||||||
if (!(block.getType().isItem() && block.getType() == mainHand.getType() || isSame(block, mainHand))) {
|
|
||||||
BauSystem.MESSAGE.send("ATTRIBUTES_CANT_COPY", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockData blockData = block.getBlockData();
|
|
||||||
List<String> attributesToCopy = new ArrayList<>();
|
|
||||||
if (block.getType() != mainHand.getType()) {
|
|
||||||
attributesToCopy.add("§8-§7 Material§8:§7 " + block.getType().name());
|
|
||||||
}
|
|
||||||
AttributeUtils.copy(blockData, attributesToCopy);
|
|
||||||
if (attributesToCopy.isEmpty()) {
|
|
||||||
BauSystem.MESSAGE.send("ATTRIBUTES_NO_COPY", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ItemMeta itemMeta = mainHand.getItemMeta();
|
|
||||||
List<String> lore = new ArrayList<>(attributesToCopy);
|
|
||||||
lore.add(0, "§eAttributes§8:");
|
|
||||||
itemMeta.setLore(lore);
|
|
||||||
mainHand.setItemMeta(itemMeta);
|
|
||||||
player.getInventory().setItemInMainHand(mainHand);
|
|
||||||
BauSystem.MESSAGE.send("ATTRIBUTES_COPIED", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSame(Block block, ItemStack itemStack) {
|
|
||||||
if (itemStack.getType() == Material.REDSTONE && block.getType() == Material.REDSTONE_WIRE) return true;
|
|
||||||
if (itemStack.getType() == Material.PLAYER_HEAD && block.getType() == Material.PLAYER_WALL_HEAD) return true;
|
|
||||||
if (itemStack.getType() == Material.ZOMBIE_HEAD && block.getType() == Material.ZOMBIE_WALL_HEAD) return true;
|
|
||||||
if (itemStack.getType() == Material.CREEPER_HEAD && block.getType() == Material.CREEPER_WALL_HEAD) return true;
|
|
||||||
if (itemStack.getType() == Material.DRAGON_HEAD && block.getType() == Material.DRAGON_WALL_HEAD) return true;
|
|
||||||
if (itemStack.getType() == Material.SKELETON_SKULL && block.getType() == Material.SKELETON_WALL_SKULL) return true;
|
|
||||||
if (itemStack.getType() == Material.WITHER_SKELETON_SKULL && block.getType() == Material.WITHER_SKELETON_WALL_SKULL) return true;
|
|
||||||
if (itemStack.getType() == Material.TORCH && block.getType() == Material.WALL_TORCH) return true;
|
|
||||||
if (itemStack.getType() == Material.SOUL_TORCH && block.getType() == Material.SOUL_WALL_TORCH) return true;
|
|
||||||
if (itemStack.getType() == Material.REDSTONE_TORCH && block.getType() == Material.REDSTONE_WALL_TORCH) return true;
|
|
||||||
if (itemStack.getType() == Material.WHEAT_SEEDS && block.getType() == Material.WHEAT) return true;
|
|
||||||
if (itemStack.getType().name().contains("_BANNER") && block.getType().name().contains("_WALL_BANNER")) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.attributescopy;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.Skull;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class AttributesPlaceListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
|
||||||
ItemStack itemStack = event.getItemInHand();
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
if (itemMeta == null) return;
|
|
||||||
List<String> strings = itemMeta.getLore();
|
|
||||||
if (strings == null) return;
|
|
||||||
if (strings.isEmpty()) return;
|
|
||||||
if (!strings.get(0).equals("§eAttributes§8:")) return;
|
|
||||||
Material type = event.getBlock().getType();
|
|
||||||
OfflinePlayer offlinePlayer = null;
|
|
||||||
if (event.getBlock().getState() instanceof Skull) {
|
|
||||||
Skull skull = (Skull) event.getBlock().getState();
|
|
||||||
offlinePlayer = skull.getOwningPlayer();
|
|
||||||
}
|
|
||||||
OfflinePlayer finalPlayerProfile = offlinePlayer;
|
|
||||||
event.setCancelled(true);
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
Material material = strings.stream()
|
|
||||||
.filter(s -> s.startsWith("§8-§7 Material§8:§7 "))
|
|
||||||
.map(s -> s.replace("§8-§7 Material§8:§7 ", ""))
|
|
||||||
.map(String::toUpperCase)
|
|
||||||
.map(s -> {
|
|
||||||
try {
|
|
||||||
return Material.valueOf(s);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.findFirst()
|
|
||||||
.orElse(type);
|
|
||||||
event.getBlock().setType(material, false);
|
|
||||||
Block block = event.getBlock();
|
|
||||||
BlockData blockData = block.getBlockData();
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
if (block.getState() instanceof Skull && finalPlayerProfile != null) {
|
|
||||||
Skull skull = (Skull) block.getState();
|
|
||||||
skull.setOwningPlayer(finalPlayerProfile);
|
|
||||||
skull.update(true, false);
|
|
||||||
}
|
|
||||||
}, 1);
|
|
||||||
AttributeUtils.paste(blockData, strings);
|
|
||||||
block.setBlockData(blockData, false);
|
|
||||||
}, 1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,11 +20,12 @@
|
|||||||
package de.steamwar.bausystem.features.autostart;
|
package de.steamwar.bausystem.features.autostart;
|
||||||
|
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.COMMAND)
|
||||||
public class AutoStartCommand extends SWCommand {
|
public class AutoStartCommand extends SWCommand {
|
||||||
|
|
||||||
public AutoStartCommand() {
|
public AutoStartCommand() {
|
||||||
@ -32,7 +33,7 @@ public class AutoStartCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Register(description = "AUTOSTART_COMMAND_HELP")
|
@Register(description = "AUTOSTART_COMMAND_HELP")
|
||||||
public void genericCommand(@Validator Player p) {
|
public void genericCommand(Player p) {
|
||||||
SWUtils.giveItemToPlayer(p, AutostartListener.getWandItem(p));
|
SWUtils.giveItemToPlayer(p, AutostartListener.getWandItem(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,15 @@
|
|||||||
package de.steamwar.bausystem.features.autostart;
|
package de.steamwar.bausystem.features.autostart;
|
||||||
|
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.BAU_GUI_ITEM)
|
||||||
public class AutoStartGuiItem extends BauGuiItem {
|
public class AutoStartGuiItem extends BauGuiItem {
|
||||||
|
|
||||||
public AutoStartGuiItem() {
|
public AutoStartGuiItem() {
|
||||||
@ -50,6 +51,6 @@ public class AutoStartGuiItem extends BauGuiItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Permission permission() {
|
public Permission permission() {
|
||||||
return Permission.BUILD;
|
return Permission.MEMBER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,34 +20,31 @@
|
|||||||
package de.steamwar.bausystem.features.autostart;
|
package de.steamwar.bausystem.features.autostart;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.RegionUtils;
|
import de.steamwar.bausystem.region.RegionUtils;
|
||||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
import de.steamwar.bausystem.region.utils.RegionType;
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
import de.steamwar.bausystem.utils.ItemUtils;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.type.Chest;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
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.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.LISTENER)
|
||||||
public class AutostartListener implements Listener {
|
public class AutostartListener implements Listener {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -68,42 +65,15 @@ public class AutostartListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
|
||||||
if (!ItemUtils.isItem(event.getItem(), "autostart")) {
|
if (!ItemUtils.isItem(event.getItem(), "autostart")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.getClickedBlock() == null) {
|
if (event.getClickedBlock() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.getClickedBlock().getBlockData() instanceof Chest) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.getClickedBlock().getType() == Material.BEDROCK) {
|
|
||||||
event.getClickedBlock().setType(Material.SLIME_BLOCK);
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
event.getClickedBlock().setType(Material.BEDROCK, false);
|
|
||||||
}, 1);
|
|
||||||
}
|
|
||||||
activate(event.getPlayer());
|
activate(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryClose(InventoryCloseEvent event) {
|
|
||||||
if (!(event.getPlayer() instanceof Player)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!Permission.BUILD.hasPermission((Player) event.getPlayer())) return;
|
|
||||||
if (!ItemUtils.isItem(event.getPlayer().getInventory().getItemInMainHand(), "autostart")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.getInventory().getLocation() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.getInventory().getLocation().getBlock().getBlockData() instanceof Chest) {
|
|
||||||
activate((Player) event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate(Player player) {
|
public void activate(Player player) {
|
||||||
Region region = Region.getRegion(player.getLocation());
|
Region region = Region.getRegion(player.getLocation());
|
||||||
if (region.isGlobal()) {
|
if (region.isGlobal()) {
|
||||||
@ -119,7 +89,7 @@ public class AutostartListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_START", player);
|
BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_START", player);
|
||||||
}
|
}
|
||||||
regionStartTime.put(region, TPSUtils.currentRealTick.get());
|
regionStartTime.put(region, TPSUtils.currentTick.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -127,24 +97,17 @@ public class AutostartListener implements Listener {
|
|||||||
if (regionStartTime.isEmpty()) {
|
if (regionStartTime.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.blockList().forEach(block -> {
|
event.blockList().forEach(block -> {
|
||||||
Region region = Region.getRegion(block.getLocation());
|
Region region = Region.getRegion(block.getLocation());
|
||||||
if (!regionStartTime.containsKey(region)) return;
|
if (!regionStartTime.containsKey(region)) return;
|
||||||
if (!region.hasType(RegionType.TESTBLOCK)) return;
|
if (!region.hasType(RegionType.TESTBLOCK)) return;
|
||||||
if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return;
|
if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return;
|
||||||
long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region);
|
long tickDiff = TPSUtils.currentTick.get() - regionStartTime.remove(region);
|
||||||
long preFightDurationInSeconds = getPreFightDurationInSeconds(region);
|
RegionUtils.message(region, player -> {
|
||||||
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT1", tickDiff);
|
return BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_RESULT1", player, new SimpleDateFormat(BauSystem.MESSAGE.parse("AUTOSTART_MESSAGE_DATE_PATTERN", player)).format(new Date(tickDiff * 50)));
|
||||||
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", preFightDurationInSeconds, ((preFightDurationInSeconds * 20) - tickDiff));
|
});
|
||||||
|
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", 30, (600 - tickDiff));
|
||||||
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT3");
|
RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT3");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPreFightDurationInSeconds(Region region) {
|
|
||||||
File file = region.gameModeConfig();
|
|
||||||
if (file == null) return 30;
|
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
|
||||||
return config.getInt("Times.PreFightDuration", 30);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,22 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.backup;
|
package de.steamwar.bausystem.features.backup;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.region.Color;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
|
||||||
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
|
|
||||||
import de.steamwar.bausystem.region.tags.Tag;
|
import de.steamwar.bausystem.region.tags.Tag;
|
||||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
import de.steamwar.command.*;
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.SWCommandUtils;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import de.steamwar.command.TypeValidator;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -46,7 +39,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.COMMAND)
|
||||||
public class BackupCommand extends SWCommand {
|
public class BackupCommand extends SWCommand {
|
||||||
|
|
||||||
public BackupCommand() {
|
public BackupCommand() {
|
||||||
@ -62,7 +55,7 @@ public class BackupCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "create", description = "BACKUP_HELP_CREATE")
|
@Register(value = "create", description = "BACKUP_HELP_CREATE")
|
||||||
public void backupCreate(@Validator("owner") Player p) {
|
public void backupCreate(@Guard Player p) {
|
||||||
Region region = Region.getRegion(p.getLocation());
|
Region region = Region.getRegion(p.getLocation());
|
||||||
if (checkGlobalRegion(region, p)) {
|
if (checkGlobalRegion(region, p)) {
|
||||||
return;
|
return;
|
||||||
@ -79,7 +72,7 @@ public class BackupCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "load", description = "BACKUP_HELP_LOAD")
|
@Register(value = "load", description = "BACKUP_HELP_LOAD")
|
||||||
public void backupLoad(@Validator("owner") Player p, @Mapper("backupName") String backupName) {
|
public void backupLoad(@Guard Player p, @Mapper("backupName") String backupName) {
|
||||||
Region region = Region.getRegion(p.getLocation());
|
Region region = Region.getRegion(p.getLocation());
|
||||||
if (checkGlobalRegion(region, p)) {
|
if (checkGlobalRegion(region, p)) {
|
||||||
return;
|
return;
|
||||||
@ -90,13 +83,7 @@ public class BackupCommand extends SWCommand {
|
|||||||
BauSystem.MESSAGE.send("BACKUP_LOAD_FAILURE", p);
|
BauSystem.MESSAGE.send("BACKUP_LOAD_FAILURE", p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EditSession editSession = new PasteBuilder(new PasteBuilder.FileProvider(backupFile))
|
region.reset(backupFile);
|
||||||
.pastePoint(region.getMinPoint().add(region.getPrototype().getSizeX() / 2, 0, region.getPrototype().getSizeZ() / 2))
|
|
||||||
.minPoint(region.getMinPoint())
|
|
||||||
.maxPoint(region.getMaxPoint())
|
|
||||||
.waterLevel(region.getWaterLevel())
|
|
||||||
.run();
|
|
||||||
region.remember(editSession);
|
|
||||||
BauSystem.MESSAGE.send("BACKUP_LOAD", p);
|
BauSystem.MESSAGE.send("BACKUP_LOAD", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +117,7 @@ public class BackupCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
SWListInv<String> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("BACKUP_INV_NAME", p), swListEntries, (clickType, s) -> {
|
SWListInv<String> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("BACKUP_INV_NAME", p), swListEntries, (clickType, s) -> {
|
||||||
p.getOpenInventory().close();
|
p.getOpenInventory().close();
|
||||||
p.performCommand("backup load " + s);
|
backupLoad(p, s);
|
||||||
});
|
});
|
||||||
swListInv.open();
|
swListInv.open();
|
||||||
}
|
}
|
||||||
@ -140,6 +127,20 @@ public class BackupCommand extends SWCommand {
|
|||||||
return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listBackup((Player) commandSender));
|
return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listBackup((Player) commandSender));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ClassGuard(value = Player.class, local = true)
|
||||||
|
public GuardChecker backupGuard() {
|
||||||
|
return (commandSender, guardCheckType, strings, s) -> {
|
||||||
|
Player player = (Player) commandSender;
|
||||||
|
if (Permission.hasPermission(player, Permission.WORLDEDIT)) {
|
||||||
|
return GuardResult.ALLOWED;
|
||||||
|
}
|
||||||
|
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
|
||||||
|
BauSystem.MESSAGE.send("BACKUP_NO_PERMS", player);
|
||||||
|
}
|
||||||
|
return GuardResult.DENIED;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> listBackup(Player p) {
|
private List<String> listBackup(Player p) {
|
||||||
Region region = Region.getRegion(p.getLocation());
|
Region region = Region.getRegion(p.getLocation());
|
||||||
if (checkGlobalRegion(region, p)) {
|
if (checkGlobalRegion(region, p)) {
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.bau;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkedInstance;
|
||||||
|
import de.steamwar.command.GuardCheckType;
|
||||||
|
import de.steamwar.command.GuardChecker;
|
||||||
|
import de.steamwar.command.GuardResult;
|
||||||
|
import de.steamwar.command.SWCommand;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@Linked(LinkageType.COMMAND)
|
||||||
|
public class BauCommand extends SWCommand {
|
||||||
|
|
||||||
|
@LinkedInstance
|
||||||
|
private BauServer bauServer;
|
||||||
|
|
||||||
|
@LinkedInstance
|
||||||
|
private InfoCommand infoCommand;
|
||||||
|
|
||||||
|
public BauCommand() {
|
||||||
|
super("bau", "b", "gs");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register(value = "info", description = "BAU_COMMAND_HELP_INFO")
|
||||||
|
public void infoCommand(Player p) {
|
||||||
|
infoCommand.sendBauInfo(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ClassGuard(value = Player.class, local = true)
|
||||||
|
public GuardChecker bauGuard() {
|
||||||
|
return (commandSender, guardCheckType, strings, s) -> {
|
||||||
|
Player p = (Player) commandSender;
|
||||||
|
if (!bauServer.getOwner().equals(p.getUniqueId())) {
|
||||||
|
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
|
||||||
|
BauSystem.MESSAGE.send("BAU_NO_WORLD", p);
|
||||||
|
}
|
||||||
|
return GuardResult.DENIED;
|
||||||
|
}
|
||||||
|
return GuardResult.ALLOWED;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -22,12 +22,12 @@ package de.steamwar.bausystem.features.bau;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.config.BauServer;
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.core.Core;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -37,7 +37,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.BAU_GUI_ITEM)
|
||||||
public class BauInfoBauGuiItem extends BauGuiItem {
|
public class BauInfoBauGuiItem extends BauGuiItem {
|
||||||
|
|
||||||
public BauInfoBauGuiItem() {
|
public BauInfoBauGuiItem() {
|
||||||
@ -59,9 +59,6 @@ public class BauInfoBauGuiItem extends BauGuiItem {
|
|||||||
if (flag == Flag.PROTECT && region.getFloorLevel() == 0) {
|
if (flag == Flag.PROTECT && region.getFloorLevel() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (flag == Flag.ITEMS && Core.getVersion() < 19) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Flag.Value<?> value = region.get(flag);
|
Flag.Value<?> value = region.get(flag);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
stringList.add(BauSystem.MESSAGE.parse("BAU_INFO_ITEM_LORE_" + flag.name(), player, BauSystem.MESSAGE.parse(value.getChatValue(), player)));
|
stringList.add(BauSystem.MESSAGE.parse("BAU_INFO_ITEM_LORE_" + flag.name(), player, BauSystem.MESSAGE.parse(value.getChatValue(), player)));
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.bau;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.command.PreviousArguments;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.techhider.TechHider;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class ForceSpectatorCommand extends SWCommand {
|
|
||||||
|
|
||||||
public ForceSpectatorCommand() {
|
|
||||||
super("forcespectator");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void forceSpectator(@Validator("supervisor") Player player, @Mapper("builder") Player other) {
|
|
||||||
Permission.forceOnlySpectator(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mapper("builder")
|
|
||||||
public TypeMapper<Player> spectatorMapper() {
|
|
||||||
return new TypeMapper<>() {
|
|
||||||
@Override
|
|
||||||
public Player map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
Player player = Bukkit.getPlayer(s);
|
|
||||||
if (player == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (Permission.BUILD.hasPermission(player) && !Permission.SUPERVISOR.hasPermission(player)) {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
|
||||||
return Bukkit.getOnlinePlayers().stream()
|
|
||||||
.filter(Permission.BUILD::hasPermission)
|
|
||||||
.filter(player -> !Permission.SUPERVISOR.hasPermission(player))
|
|
||||||
.map(Player::getName)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +1,44 @@
|
|||||||
package de.steamwar.bausystem.features.bau;
|
package de.steamwar.bausystem.features.bau;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.bausystem.config.BauServer;
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
|
import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkedInstance;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.core.TPSWatcher;
|
import de.steamwar.core.TPSWatcher;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.linkage.LinkedInstance;
|
|
||||||
import de.steamwar.sql.BauweltMember;
|
import de.steamwar.sql.BauweltMember;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
|
||||||
@Linked
|
import static de.steamwar.bausystem.features.tpslimit.TPSWarpUtils.getTps;
|
||||||
|
|
||||||
|
@Linked(LinkageType.COMMAND)
|
||||||
public class InfoCommand extends SWCommand {
|
public class InfoCommand extends SWCommand {
|
||||||
|
|
||||||
@LinkedInstance
|
@LinkedInstance
|
||||||
public BauServer bauServer;
|
private BauServer bauServer;
|
||||||
|
|
||||||
public InfoCommand() {
|
public InfoCommand() {
|
||||||
super("bauinfo");
|
super("bauinfo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(description = "BAU_INFO_COMMAND_HELP")
|
@Register(help = true)
|
||||||
|
public void genericHelp(Player p, String... args) {
|
||||||
|
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_HELP", p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
public void genericCommand(Player p) {
|
public void genericCommand(Player p) {
|
||||||
|
sendBauInfo(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBauInfo(Player p) {
|
||||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_OWNER", p, SteamwarUser.get(bauServer.getOwnerID()).getUserName());
|
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_OWNER", p, SteamwarUser.get(bauServer.getOwnerID()).getUserName());
|
||||||
Region region = Region.getRegion(p.getLocation());
|
Region region = Region.getRegion(p.getLocation());
|
||||||
for (Flag flag : Flag.getFlags()) {
|
for (Flag flag : Flag.getFlags()) {
|
||||||
@ -39,48 +51,29 @@ public class InfoCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Permission.BUILD.hasPermission(p)) {
|
|
||||||
List<BauweltMember> members = BauweltMember.getMembers(bauServer.getOwnerID());
|
List<BauweltMember> members = BauweltMember.getMembers(bauServer.getOwnerID());
|
||||||
Map<Permission, List<BauweltMember>> memberByPermission = new HashMap<>();
|
StringBuilder membermessage = new StringBuilder();
|
||||||
members.forEach(member -> {
|
membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p));
|
||||||
if (Permission.SUPERVISOR.hasPermission(member)) {
|
|
||||||
memberByPermission.computeIfAbsent(Permission.SUPERVISOR, __ -> new ArrayList<>()).add(member);
|
for (BauweltMember member : members) {
|
||||||
} else if (Permission.BUILD.hasPermission(member)) {
|
membermessage.append(BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_INFO", p,
|
||||||
memberByPermission.computeIfAbsent(Permission.BUILD, __ -> new ArrayList<>()).add(member);
|
SteamwarUser.get(member.getMemberID()).getUserName(),
|
||||||
} else {
|
member.isWorldEdit() ? BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WE_ALLOW", p) : BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WE_DISALLOW", p),
|
||||||
memberByPermission.computeIfAbsent(Permission.MEMBER, __ -> new ArrayList<>()).add(member);
|
member.isWorld() ? BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WORLD_ALLOW", p) : BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WORLD_DISALLOW", p)
|
||||||
}
|
));
|
||||||
});
|
|
||||||
|
|
||||||
List<BauweltMember> supervisor = memberByPermission.getOrDefault(Permission.SUPERVISOR, Collections.emptyList());
|
|
||||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_MEMBER", p, "§eSupervisor", supervisor.size(), supervisor.isEmpty() ? "§8<none>" : joining(supervisor));
|
|
||||||
|
|
||||||
List<BauweltMember> builder = memberByPermission.getOrDefault(Permission.BUILD, Collections.emptyList());
|
|
||||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_MEMBER", p, "§6Builder", builder.size(), builder.isEmpty() ? "§8<none>" : joining(builder));
|
|
||||||
|
|
||||||
List<BauweltMember> spectator = memberByPermission.getOrDefault(Permission.MEMBER, Collections.emptyList());
|
|
||||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_MEMBER", p, "§7Spectator", spectator.size(), spectator.isEmpty() ? "§8<none>" : joining(spectator));
|
|
||||||
}
|
}
|
||||||
|
p.sendMessage(membermessage.toString());
|
||||||
|
|
||||||
StringBuilder tpsMessage = new StringBuilder();
|
StringBuilder tpsMessage = new StringBuilder();
|
||||||
tpsMessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_TPS", p));
|
tpsMessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_TPS", p));
|
||||||
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND));
|
tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.ONE_SECOND));
|
||||||
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS));
|
tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.TEN_SECONDS));
|
||||||
|
if (!TPSWarpUtils.isWarping()) {
|
||||||
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE));
|
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE));
|
||||||
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES));
|
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES));
|
||||||
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES));
|
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES));
|
||||||
|
}
|
||||||
p.sendMessage(tpsMessage.toString());
|
p.sendMessage(tpsMessage.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String joining(List<BauweltMember> bauweltMembers) {
|
|
||||||
StringBuilder st = new StringBuilder();
|
|
||||||
for (int i = 0; i < bauweltMembers.size(); i++) {
|
|
||||||
if (i != 0) {
|
|
||||||
st.append("§8, ");
|
|
||||||
}
|
|
||||||
st.append("§7");
|
|
||||||
st.append(SteamwarUser.get(bauweltMembers.get(i).getMemberID()).getUserName());
|
|
||||||
}
|
|
||||||
return st.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.cannon;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.cannon.depth.Depth;
|
|
||||||
import de.steamwar.bausystem.features.cannon.depth.DepthManager;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class CannonDetector implements Listener {
|
|
||||||
|
|
||||||
private Map<TNTPrimed, Vector> velocities = new HashMap<>();
|
|
||||||
private Map<TNTPrimed, Set<UUID>> propulsionOfProjectile = new HashMap<>();
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
|
||||||
if (!(event.getEntity() instanceof TNTPrimed)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TNTPrimed tnt = (TNTPrimed) event.getEntity();
|
|
||||||
propulsionOfProjectile.remove(tnt);
|
|
||||||
|
|
||||||
DepthManager.update(tnt, event.blockList());
|
|
||||||
|
|
||||||
List<TNTPrimed> tnts = Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)
|
|
||||||
.stream()
|
|
||||||
.filter(entity -> entity != tnt)
|
|
||||||
.filter(entity -> entity.getFuseTicks() > 1)
|
|
||||||
.filter(entity -> entity.getLocation().distance(event.getLocation()) <= 8)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (tnts.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isEmpty = velocities.isEmpty();
|
|
||||||
tnts.forEach(tntPrimed -> {
|
|
||||||
velocities.put(tntPrimed, tntPrimed.getVelocity().clone());
|
|
||||||
propulsionOfProjectile.computeIfAbsent(tntPrimed, __ -> new HashSet<>()).add(tnt.getUniqueId());
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!isEmpty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
Map<CannonKey, List<TNTPrimed>> grouped = new HashMap<>();
|
|
||||||
velocities.forEach((tntPrimed, vector) -> {
|
|
||||||
boolean xBiggest = Math.abs(vector.getX()) > Math.abs(vector.getZ());
|
|
||||||
boolean zBiggest = Math.abs(vector.getZ()) > Math.abs(vector.getX());
|
|
||||||
Vector vec = new Vector(xBiggest ? Math.signum(vector.getX()) : 0, Math.round(vector.getY() * 100), zBiggest ? Math.signum(vector.getZ()) : 0);
|
|
||||||
grouped.computeIfAbsent(new CannonKey(propulsionOfProjectile.get(tntPrimed), vec), ignored -> new ArrayList<>()).add(tntPrimed);
|
|
||||||
});
|
|
||||||
grouped.forEach((cannonKey, tntPrimeds) -> {
|
|
||||||
if (tntPrimeds.size() <= 5) return;
|
|
||||||
Region region = Region.getRegion(tntPrimeds.get(0).getLocation());
|
|
||||||
if (region.isGlobal()) return;
|
|
||||||
if (!region.hasType(RegionType.TESTBLOCK)) return;
|
|
||||||
Depth depth = new Depth(region);
|
|
||||||
DepthManager.init(tntPrimeds, depth);
|
|
||||||
});
|
|
||||||
velocities.clear();
|
|
||||||
}, 1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.cannon;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
@Getter
|
|
||||||
public final class CannonKey {
|
|
||||||
private Set<UUID> propulsions;
|
|
||||||
private Vector velocityVector;
|
|
||||||
}
|
|
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.cannon.depth;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.region.RegionUtils;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class Depth {
|
|
||||||
|
|
||||||
private Region region;
|
|
||||||
private Vector minVector = null;
|
|
||||||
private Vector maxVector = null;
|
|
||||||
private int tntCount = 0;
|
|
||||||
|
|
||||||
public Depth(Region region) {
|
|
||||||
this.region = region;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(List<Block> blocks) {
|
|
||||||
List<Block> blocksList = blocks.stream()
|
|
||||||
.filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
tntCount++;
|
|
||||||
for (Block block : blocksList) {
|
|
||||||
internalUpdate(block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void finish() {
|
|
||||||
if (maxVector == null || minVector == null) return;
|
|
||||||
Vector dimensions = maxVector.subtract(minVector);
|
|
||||||
dimensions.setX(Math.abs(dimensions.getX()));
|
|
||||||
dimensions.setY(Math.abs(dimensions.getY()));
|
|
||||||
dimensions.setZ(Math.abs(dimensions.getZ()));
|
|
||||||
|
|
||||||
RegionUtils.message(region, player -> {
|
|
||||||
player.spigot().sendMessage(getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, tntCount));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void internalUpdate(Block block) {
|
|
||||||
if (minVector == null) {
|
|
||||||
minVector = block.getLocation().toVector();
|
|
||||||
}
|
|
||||||
minVector.setX(Math.min(minVector.getX(), block.getX()));
|
|
||||||
minVector.setY(Math.min(minVector.getY(), block.getY()));
|
|
||||||
minVector.setZ(Math.min(minVector.getZ(), block.getZ()));
|
|
||||||
|
|
||||||
if (maxVector == null) {
|
|
||||||
maxVector = block.getLocation().toVector();
|
|
||||||
}
|
|
||||||
maxVector.setX(Math.max(maxVector.getX(), block.getX()));
|
|
||||||
maxVector.setY(Math.max(maxVector.getY(), block.getY()));
|
|
||||||
maxVector.setZ(Math.max(maxVector.getZ(), block.getZ()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BaseComponent[] getMessage(Player player, int x, int y, int z, int tntCount) {
|
|
||||||
final Set<Integer> dimensions = new HashSet<>();
|
|
||||||
dimensions.add(x);
|
|
||||||
dimensions.add(y);
|
|
||||||
dimensions.add(z);
|
|
||||||
|
|
||||||
int max = getMax(dimensions);
|
|
||||||
|
|
||||||
TextComponent headerComponent = new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_MESSAGE", player));
|
|
||||||
|
|
||||||
TextComponent depthComponent = new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_COUNT", player, x == max ? "§e" : "§7", x, y == max ? "§e" : "§7", y, z == max ? "§e" : "§7", z));
|
|
||||||
depthComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_HOVER", player))}));
|
|
||||||
|
|
||||||
TextComponent tntComponent = new TextComponent(BauSystem.MESSAGE.parse("DEPTH_COUNTER_TNT", player, tntCount));
|
|
||||||
|
|
||||||
return new BaseComponent[]{headerComponent, depthComponent, tntComponent};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getMax(Set<Integer> values) {
|
|
||||||
return values.stream().max(Integer::compare).orElse(0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.cannon.depth;
|
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class DepthManager {
|
|
||||||
|
|
||||||
private Map<TNTPrimed, Depth> depths = new HashMap<>();
|
|
||||||
|
|
||||||
public void init(List<TNTPrimed> list, Depth depth) {
|
|
||||||
for (TNTPrimed tnt : list) {
|
|
||||||
depths.putIfAbsent(tnt, depth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(TNTPrimed tnt, List<Block> blocks) {
|
|
||||||
Depth depth = depths.remove(tnt);
|
|
||||||
if (depth == null) return;
|
|
||||||
depth.update(blocks);
|
|
||||||
if (depths.containsValue(depth)) return;
|
|
||||||
depth.finish();
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,7 +28,6 @@ import lombok.experimental.UtilityClass;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -41,9 +40,6 @@ public class Countingwand {
|
|||||||
public static ItemStack getWandItem(Player player) {
|
public static ItemStack getWandItem(Player player) {
|
||||||
ItemStack itemStack = new SWItem(Material.STICK, BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE1", player), BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE2", player)), false, null).getItemStack();
|
ItemStack itemStack = new SWItem(Material.STICK, BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE1", player), BauSystem.MESSAGE.parse("COUNTINGWAND_ITEM_LORE2", player)), false, null).getItemStack();
|
||||||
ItemUtils.setItem(itemStack, "countingwand");
|
ItemUtils.setItem(itemStack, "countingwand");
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
itemMeta.setCustomModelData(1);
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,12 +20,13 @@
|
|||||||
package de.steamwar.bausystem.features.countingwand;
|
package de.steamwar.bausystem.features.countingwand;
|
||||||
|
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.COMMAND)
|
||||||
public class CountingwandCommand extends SWCommand {
|
public class CountingwandCommand extends SWCommand {
|
||||||
|
|
||||||
public CountingwandCommand() {
|
public CountingwandCommand() {
|
||||||
|
@ -20,14 +20,15 @@
|
|||||||
package de.steamwar.bausystem.features.countingwand;
|
package de.steamwar.bausystem.features.countingwand;
|
||||||
|
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.BAU_GUI_ITEM)
|
||||||
public class CountingwandGuiItem extends BauGuiItem {
|
public class CountingwandGuiItem extends BauGuiItem {
|
||||||
|
|
||||||
public CountingwandGuiItem() {
|
public CountingwandGuiItem() {
|
||||||
@ -48,6 +49,6 @@ public class CountingwandGuiItem extends BauGuiItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Permission permission() {
|
public Permission permission() {
|
||||||
return Permission.MEMBER;
|
return Permission.WORLDEDIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,8 +19,9 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.countingwand;
|
package de.steamwar.bausystem.features.countingwand;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.region.Point;
|
import de.steamwar.bausystem.region.Point;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.FluidCollisionMode;
|
import org.bukkit.FluidCollisionMode;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -33,7 +34,7 @@ import org.bukkit.util.RayTraceResult;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.LISTENER)
|
||||||
public class CountingwandListener implements Listener {
|
public class CountingwandListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -1,141 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.design.endstone;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.entity.REntity;
|
|
||||||
import de.steamwar.entity.REntityServer;
|
|
||||||
import de.steamwar.entity.RFallingBlockEntity;
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class DesignEndStone {
|
|
||||||
|
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
|
||||||
|
|
||||||
private int minX, minY, minZ, maxX, maxY, maxZ;
|
|
||||||
private REntityServer entityServer = new REntityServer();
|
|
||||||
private List<REntity> entities = new ArrayList<>();
|
|
||||||
private Set<Location> locations = new HashSet<>();
|
|
||||||
private boolean wsOrAs;
|
|
||||||
private double maxBlastResistance;
|
|
||||||
|
|
||||||
public DesignEndStone(Region region) {
|
|
||||||
this.minX = region.getMinPointBuild().getX();
|
|
||||||
this.minY = region.getMinPointBuild().getY();
|
|
||||||
this.minZ = region.getMinPointBuild().getZ();
|
|
||||||
this.maxX = region.getMaxPointBuild().getX();
|
|
||||||
this.maxY = region.getMaxPointBuild().getY();
|
|
||||||
this.maxZ = region.getMaxPointBuild().getZ();
|
|
||||||
wsOrAs = region.getName().startsWith("ws") || region.getName().startsWith("as");
|
|
||||||
maxBlastResistance = wsOrAs ? 6.1 : 9.0;
|
|
||||||
|
|
||||||
entityServer.setCallback((player, rEntity, entityAction) -> {
|
|
||||||
if (entityAction != REntityServer.EntityAction.ATTACK) return;
|
|
||||||
Location location = new Location(WORLD, rEntity.getX(), rEntity.getY(), rEntity.getZ());
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
location.getBlock().breakNaturally();
|
|
||||||
calc();
|
|
||||||
}, 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void calc() {
|
|
||||||
entities.forEach(REntity::die);
|
|
||||||
entities.clear();
|
|
||||||
locations.clear();
|
|
||||||
|
|
||||||
calc(minX, minY, minZ, maxX, maxY, minZ, 0, 0, 1, maxZ - minZ);
|
|
||||||
calc(minX, minY, maxZ, maxX, maxY, maxZ, 0, 0, -1, maxZ - minZ);
|
|
||||||
calc(minX, minY, minZ, minX, maxY, maxZ, 1, 0, 0, maxX - minX);
|
|
||||||
calc(maxX, minY, minZ, maxX, maxY, maxZ, -1, 0, 0, maxX - minX);
|
|
||||||
if (wsOrAs) {
|
|
||||||
calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY + 1);
|
|
||||||
} else {
|
|
||||||
int airBlocks = 0;
|
|
||||||
double minAirBlocks = (maxX - minX) * (maxZ - minZ) * 0.1;
|
|
||||||
for (int x = minX; x < maxX; x++) {
|
|
||||||
for (int z = minZ; z < maxZ; z++) {
|
|
||||||
if (WORLD.getBlockAt(x, minY, z).getType().isAir()) {
|
|
||||||
airBlocks++;
|
|
||||||
if (airBlocks > minAirBlocks) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (airBlocks > minAirBlocks) {
|
|
||||||
calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
calc(minX, maxY, minZ, maxX, maxY, maxZ, 0, -1, 0, maxY - minY + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calc(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int dirX, int dirY, int dirZ, int steps) {
|
|
||||||
for (int x = minX; x <= maxX; x++) {
|
|
||||||
for (int y = minY; y <= maxY; y++) {
|
|
||||||
for (int z = minZ; z <= maxZ; z++) {
|
|
||||||
for (int step = 0; step < steps; step++) {
|
|
||||||
int cx = x + step * dirX;
|
|
||||||
int cy = y + step * dirY;
|
|
||||||
int cz = z + step * dirZ;
|
|
||||||
Material material = WORLD.getBlockAt(cx, cy, cz).getType();
|
|
||||||
|
|
||||||
if (material != Material.WATER && material != Material.LAVA && material.getBlastResistance() >= maxBlastResistance) {
|
|
||||||
Location location = new Location(WORLD, cx + 0.5, cy, cz + 0.5);
|
|
||||||
if (!locations.add(location)) break;
|
|
||||||
RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.RED_STAINED_GLASS);
|
|
||||||
entity.setNoGravity(true);
|
|
||||||
entity.setGlowing(true);
|
|
||||||
entities.add(entity);
|
|
||||||
break;
|
|
||||||
} else if (!material.isAir() && material != Material.WATER && material != Material.LAVA) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggle(Player player) {
|
|
||||||
if (entityServer.getPlayers().contains(player)) {
|
|
||||||
entityServer.removePlayer(player);
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("DESIGN_ENDSTONE_DISABLE", player, ChatMessageType.ACTION_BAR);
|
|
||||||
} else {
|
|
||||||
entityServer.addPlayer(player);
|
|
||||||
calc();
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("DESIGN_ENDSTONE_ENABLE", player, ChatMessageType.ACTION_BAR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removePlayer(Player player) {
|
|
||||||
entityServer.removePlayer(player);
|
|
||||||
return entityServer.getPlayers().isEmpty();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.design.endstone;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
|
||||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class DesignEndStoneCommand extends SWCommand implements Listener {
|
|
||||||
|
|
||||||
public DesignEndStoneCommand() {
|
|
||||||
super("designendstone");
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<Region, DesignEndStone> designEndStoneMap = new HashMap<>();
|
|
||||||
|
|
||||||
@Register(description = "DESIGN_ENDSTONE_COMMAND_HELP")
|
|
||||||
public void genericCommand(@Validator Player player) {
|
|
||||||
Region region = Region.getRegion(player.getLocation());
|
|
||||||
if (!region.hasType(RegionType.BUILD)) {
|
|
||||||
BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
designEndStoneMap.computeIfAbsent(region, DesignEndStone::new).toggle(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
disableDesignEndStone(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
|
||||||
event.getNewSpectator().forEach(this::disableDesignEndStone);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void disableDesignEndStone(Player player) {
|
|
||||||
new HashSet<>(designEndStoneMap.entrySet()).forEach(regionDesignEndStoneEntry -> {
|
|
||||||
if (regionDesignEndStoneEntry.getValue().removePlayer(player)) {
|
|
||||||
designEndStoneMap.remove(regionDesignEndStoneEntry.getKey());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
|
||||||
update(event.getBlock().getLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
|
||||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
update(event.getBlock().getLocation());
|
|
||||||
}, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void update(Location location) {
|
|
||||||
Region region = Region.getRegion(location);
|
|
||||||
DesignEndStone designEndStone = designEndStoneMap.get(region);
|
|
||||||
if (designEndStone == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
designEndStone.calc();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.detonator;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.shared.AbstractEntity;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public interface AbstractDetonatorEntity extends AbstractEntity {
|
||||||
|
|
||||||
|
void display(Player player);
|
||||||
|
|
||||||
|
boolean hide(Player player, boolean always);
|
||||||
|
|
||||||
|
int getId();
|
||||||
|
|
||||||
|
Entity getBukkitEntity();
|
||||||
|
}
|
@ -25,8 +25,7 @@ import de.steamwar.bausystem.configplayer.Config;
|
|||||||
import de.steamwar.bausystem.features.autostart.AutostartListener;
|
import de.steamwar.bausystem.features.autostart.AutostartListener;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.bausystem.utils.NMSWrapper;
|
||||||
import de.steamwar.entity.RFallingBlockEntity;
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -45,7 +44,7 @@ import java.util.*;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class Detonator {
|
public class Detonator {
|
||||||
|
|
||||||
private static final Map<Player, REntityServer> ENTITIES_MAP = new HashMap<>();
|
private static final Map<Player, List<AbstractDetonatorEntity>> ENTITIES_MAP = new HashMap<>();
|
||||||
private static final Vector HALF = new Vector(0.5, 0, 0.5);
|
private static final Vector HALF = new Vector(0.5, 0, 0.5);
|
||||||
|
|
||||||
public static boolean isDetonator(ItemStack itemStack) {
|
public static boolean isDetonator(ItemStack itemStack) {
|
||||||
@ -53,24 +52,18 @@ public class Detonator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void showDetonator(Player p, List<Location> locs) {
|
public static void showDetonator(Player p, List<Location> locs) {
|
||||||
if (ENTITIES_MAP.containsKey(p)) return;
|
List<AbstractDetonatorEntity> entities = new LinkedList<>();
|
||||||
REntityServer entities = new REntityServer();
|
locs.stream().map(Location::toVector).forEach(vector -> entities.add(NMSWrapper.impl.constructDetonator(p.getWorld(), vector.add(HALF))));
|
||||||
entities.setCallback((player, rEntity, entityAction) -> {
|
entities.forEach(abstractDetonatorEntity -> abstractDetonatorEntity.display(p));
|
||||||
Vector vector = new Vector(rEntity.getX(), rEntity.getY(), rEntity.getZ());
|
ENTITIES_MAP.putIfAbsent(p, entities);
|
||||||
DetonatorListener.addLocationToDetonator(vector.toLocation(player.getWorld()).getBlock().getLocation(), player);
|
|
||||||
DetonatorListener.HAS_UPDATED.add(player);
|
|
||||||
});
|
|
||||||
entities.addPlayer(p);
|
|
||||||
ENTITIES_MAP.put(p, entities);
|
|
||||||
|
|
||||||
locs.forEach(location -> {
|
|
||||||
RFallingBlockEntity entity = new RFallingBlockEntity(entities, location.clone().add(HALF), Material.RED_STAINED_GLASS);
|
|
||||||
entity.setNoGravity(true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void hideDetonator(Player p) {
|
public static void hideDetonator(Player p) {
|
||||||
ENTITIES_MAP.remove(p).close();
|
ENTITIES_MAP.remove(p).forEach(abstractDetonatorEntity -> abstractDetonatorEntity.hide(p, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<AbstractDetonatorEntity> getDetoEntities(Player p) {
|
||||||
|
return ENTITIES_MAP.getOrDefault(p, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasActiveDetonatorShow(Player p) {
|
public static boolean hasActiveDetonatorShow(Player p) {
|
||||||
@ -199,23 +192,34 @@ public class Detonator {
|
|||||||
switch (block.getType()) {
|
switch (block.getType()) {
|
||||||
case LEVER:
|
case LEVER:
|
||||||
return Detoblock.SWITCH;
|
return Detoblock.SWITCH;
|
||||||
|
case ACACIA_BUTTON:
|
||||||
|
case BIRCH_BUTTON:
|
||||||
|
case DARK_OAK_BUTTON:
|
||||||
|
case JUNGLE_BUTTON:
|
||||||
|
case OAK_BUTTON:
|
||||||
|
case SPRUCE_BUTTON:
|
||||||
|
return Detoblock.WOOD_BUTTON;
|
||||||
|
case STONE_BUTTON:
|
||||||
|
return Detoblock.STONE_BUTTON;
|
||||||
|
case ACACIA_PRESSURE_PLATE:
|
||||||
|
case BIRCH_PRESSURE_PLATE:
|
||||||
|
case DARK_OAK_PRESSURE_PLATE:
|
||||||
|
case JUNGLE_PRESSURE_PLATE:
|
||||||
|
case OAK_PRESSURE_PLATE:
|
||||||
|
case SPRUCE_PRESSURE_PLATE:
|
||||||
|
case STONE_PRESSURE_PLATE:
|
||||||
|
return Detoblock.PRESSURE_PLATE;
|
||||||
|
case HEAVY_WEIGHTED_PRESSURE_PLATE:
|
||||||
|
case LIGHT_WEIGHTED_PRESSURE_PLATE:
|
||||||
|
return Detoblock.WEIGHTED_PRESSURE_PLATE;
|
||||||
case TRIPWIRE:
|
case TRIPWIRE:
|
||||||
return Detoblock.TRIPWIRE;
|
return Detoblock.TRIPWIRE;
|
||||||
case NOTE_BLOCK:
|
case NOTE_BLOCK:
|
||||||
return Detoblock.NOTEBLOCK;
|
return Detoblock.NOTEBLOCK;
|
||||||
case DAYLIGHT_DETECTOR:
|
case DAYLIGHT_DETECTOR:
|
||||||
return Detoblock.DAYLIGHTSENSOR;
|
return Detoblock.DAYLIGHTSENSOR;
|
||||||
case HEAVY_WEIGHTED_PRESSURE_PLATE:
|
|
||||||
case LIGHT_WEIGHTED_PRESSURE_PLATE:
|
|
||||||
return Detoblock.WEIGHTED_PRESSURE_PLATE;
|
|
||||||
default:
|
default:
|
||||||
if (block.getType().name().contains("STONE_BUTTON")) {
|
if (block.getBlockData() instanceof Powerable) {
|
||||||
return Detoblock.STONE_BUTTON;
|
|
||||||
} else if (block.getType().name().contains("BUTTON")) {
|
|
||||||
return Detoblock.WOOD_BUTTON;
|
|
||||||
} else if (block.getType().name().contains("PRESSURE_PLATE")) {
|
|
||||||
return Detoblock.PRESSURE_PLATE;
|
|
||||||
} else if (block.getBlockData() instanceof Powerable) {
|
|
||||||
return Detoblock.POWERABLE;
|
return Detoblock.POWERABLE;
|
||||||
} else {
|
} else {
|
||||||
return Detoblock.INVALID;
|
return Detoblock.INVALID;
|
||||||
|
@ -20,13 +20,14 @@
|
|||||||
package de.steamwar.bausystem.features.detonator;
|
package de.steamwar.bausystem.features.detonator;
|
||||||
|
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.BAU_GUI_ITEM)
|
||||||
public class DetonatorBauGuiItem extends BauGuiItem {
|
public class DetonatorBauGuiItem extends BauGuiItem {
|
||||||
|
|
||||||
public DetonatorBauGuiItem() {
|
public DetonatorBauGuiItem() {
|
||||||
@ -47,6 +48,6 @@ public class DetonatorBauGuiItem extends BauGuiItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Permission permission() {
|
public Permission permission() {
|
||||||
return Permission.BUILD;
|
return Permission.MEMBER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,10 @@ import de.steamwar.bausystem.SWUtils;
|
|||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
import de.steamwar.bausystem.utils.ItemUtils;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -34,7 +35,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.COMMAND)
|
||||||
public class DetonatorCommand extends SWCommand {
|
public class DetonatorCommand extends SWCommand {
|
||||||
|
|
||||||
public static ItemStack getWAND(Player player) {
|
public static ItemStack getWAND(Player player) {
|
||||||
@ -46,24 +47,23 @@ public class DetonatorCommand extends SWCommand {
|
|||||||
meta.setLore(Arrays.asList(BauSystem.MESSAGE.parse("DETONATOR_WAND_LORE_1", player),
|
meta.setLore(Arrays.asList(BauSystem.MESSAGE.parse("DETONATOR_WAND_LORE_1", player),
|
||||||
BauSystem.MESSAGE.parse("DETONATOR_WAND_LORE_2", player),
|
BauSystem.MESSAGE.parse("DETONATOR_WAND_LORE_2", player),
|
||||||
BauSystem.MESSAGE.parse("DETONATOR_WAND_LORE_3", player)));
|
BauSystem.MESSAGE.parse("DETONATOR_WAND_LORE_3", player)));
|
||||||
meta.setCustomModelData(3);
|
|
||||||
|
|
||||||
wand.setItemMeta(meta);
|
wand.setItemMeta(meta);
|
||||||
ItemUtils.setItem(wand, "detonator");
|
ItemUtils.setItem(wand, "detonator");
|
||||||
return wand;
|
return wand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DetonatorCommand() {
|
protected DetonatorCommand() {
|
||||||
super("detonator", "dt");
|
super("detonator", "dt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "wand", description = "DETONATOR_HELP_WAND")
|
@Register(value = "wand", description = "DETONATOR_HELP_WAND")
|
||||||
public void giveWand(@Validator Player p) {
|
public void giveWand(Player p) {
|
||||||
SWUtils.giveItemToPlayer(p, getWAND(p));
|
SWUtils.giveItemToPlayer(p, getWAND(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "click", description = "DETONATOR_HELP_CLICK")
|
@Register(value = "click", description = "DETONATOR_HELP_CLICK")
|
||||||
public void clickDetonator(@Validator Player p) {
|
public void clickDetonator(Player p) {
|
||||||
Detonator.activateDetonator(new ItemStorage(p));
|
Detonator.activateDetonator(new ItemStorage(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,12 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.detonator;
|
package de.steamwar.bausystem.features.detonator;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -37,14 +39,39 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
|||||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.LISTENER)
|
||||||
public class DetonatorListener implements Listener {
|
public class DetonatorListener implements Listener {
|
||||||
|
|
||||||
static final Set<Player> HAS_UPDATED = new HashSet<>();
|
public static final Class<?> useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity");
|
||||||
|
private static final Reflection.FieldAccessor<Integer> entityIdFieldAccessor = Reflection.getField(useEntity, int.class, 0);
|
||||||
|
|
||||||
static void addLocationToDetonator(Location location, Player p) {
|
private static final Set<Player> HAS_UPDATED = new HashSet<>();
|
||||||
|
|
||||||
|
public DetonatorListener() {
|
||||||
|
ProtocolAPI.setIncomingHandler(useEntity, (player, o) -> {
|
||||||
|
List<AbstractDetonatorEntity> entities = Detonator.getDetoEntities(player);
|
||||||
|
if (entities.isEmpty()) {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
int entityId = entityIdFieldAccessor.get(o);
|
||||||
|
AbstractDetonatorEntity entity = entities.stream().filter(abstractDetonatorEntity -> abstractDetonatorEntity.getId() == entityId).findFirst().orElse(null);
|
||||||
|
|
||||||
|
if (entity == null) {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location location = entity.getBukkitEntity().getLocation().getBlock().getLocation();
|
||||||
|
addLocationToDetonator(location, player);
|
||||||
|
HAS_UPDATED.add(player);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addLocationToDetonator(Location location, Player p) {
|
||||||
Detoblock detoblock = Detonator.getBlock(location.getBlock());
|
Detoblock detoblock = Detonator.getBlock(location.getBlock());
|
||||||
if (detoblock == Detoblock.INVALID) {
|
if (detoblock == Detoblock.INVALID) {
|
||||||
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("DETONATOR_INVALID_BLOCK", p));
|
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("DETONATOR_INVALID_BLOCK", p));
|
||||||
@ -66,7 +93,6 @@ public class DetonatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
|
||||||
Player p = event.getPlayer();
|
Player p = event.getPlayer();
|
||||||
if (Detonator.isDetonator(p.getInventory().getItemInMainHand())) {
|
if (Detonator.isDetonator(p.getInventory().getItemInMainHand())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -77,7 +103,6 @@ public class DetonatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
|
||||||
if (!Detonator.isDetonator(event.getItem())) {
|
if (!Detonator.isDetonator(event.getItem())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -92,7 +117,7 @@ public class DetonatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer()) ||!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
if (!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
||||||
if (Detonator.hasActiveDetonatorShow(event.getPlayer())) {
|
if (Detonator.hasActiveDetonatorShow(event.getPlayer())) {
|
||||||
Detonator.hideDetonator(event.getPlayer());
|
Detonator.hideDetonator(event.getPlayer());
|
||||||
}
|
}
|
||||||
@ -113,7 +138,6 @@ public class DetonatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
|
||||||
if (Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
if (Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) {
|
||||||
HAS_UPDATED.add(event.getPlayer());
|
HAS_UPDATED.add(event.getPlayer());
|
||||||
}
|
}
|
||||||
@ -121,7 +145,6 @@ public class DetonatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
|
||||||
if (Detonator.isDetonator(event.getMainHandItem()) || Detonator.isDetonator(event.getOffHandItem())) {
|
if (Detonator.isDetonator(event.getMainHandItem()) || Detonator.isDetonator(event.getOffHandItem())) {
|
||||||
HAS_UPDATED.add(event.getPlayer());
|
HAS_UPDATED.add(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
import de.steamwar.bausystem.features.gui.editor.BauGuiMapping;
|
import de.steamwar.bausystem.features.gui.editor.BauGuiMapping;
|
||||||
import de.steamwar.bausystem.linkage.LinkageUtils;
|
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -38,13 +38,9 @@ import java.util.*;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class BauGUI {
|
public class BauGUI {
|
||||||
|
|
||||||
|
@Getter
|
||||||
private static final Map<Integer, BauGuiItem> ITEMS = new HashMap<>();
|
private static final Map<Integer, BauGuiItem> ITEMS = new HashMap<>();
|
||||||
|
|
||||||
public static Map<Integer, BauGuiItem> getITEMS() {
|
|
||||||
if (ITEMS.isEmpty()) LinkageUtils.linkGUIItems();
|
|
||||||
return ITEMS;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Set<Player> OPEN_INVS = new HashSet<>();
|
private static final Set<Player> OPEN_INVS = new HashSet<>();
|
||||||
private static boolean updating = false;
|
private static boolean updating = false;
|
||||||
|
|
||||||
@ -60,6 +56,7 @@ public class BauGUI {
|
|||||||
if (ITEMS.containsKey(item.getId())) {
|
if (ITEMS.containsKey(item.getId())) {
|
||||||
throw new IllegalArgumentException("Duplicate Id Key: " + item.getId() + ". From Classes: " + ITEMS.get(item.getId()).getClass().getName() + " and " + item.getClass().getName());
|
throw new IllegalArgumentException("Duplicate Id Key: " + item.getId() + ". From Classes: " + ITEMS.get(item.getId()).getClass().getName() + " and " + item.getClass().getName());
|
||||||
}
|
}
|
||||||
|
System.out.println("Added Item: " + item.getId());
|
||||||
ITEMS.put(item.getId(), item);
|
ITEMS.put(item.getId(), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +66,7 @@ public class BauGUI {
|
|||||||
}
|
}
|
||||||
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
|
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
|
||||||
SWInventory inv = new SWInventory(p, mapping.getSize(), BauSystem.MESSAGE.parse("GUI_NAME", p));
|
SWInventory inv = new SWInventory(p, mapping.getSize(), BauSystem.MESSAGE.parse("GUI_NAME", p));
|
||||||
getITEMS().values().forEach(item -> {
|
ITEMS.values().forEach(item -> {
|
||||||
if (!mapping.isShown(item.getId())) {
|
if (!mapping.isShown(item.getId())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -81,7 +78,7 @@ public class BauGUI {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.closeInventory();
|
p.closeInventory();
|
||||||
BauSystem.MESSAGE.send("NO_PERMISSION", p);
|
BauSystem.MESSAGE.send("GUI_NO_PERMISSION", p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -108,13 +105,26 @@ public class BauGUI {
|
|||||||
if (!permission.hasPermission(p)) {
|
if (!permission.hasPermission(p)) {
|
||||||
List<String> lore = meta.getLore();
|
List<String> lore = meta.getLore();
|
||||||
if (lore == null) {
|
if (lore == null) {
|
||||||
lore = Collections.singletonList(BauSystem.MESSAGE.parse("NO_PERMISSION", p));
|
lore = Collections.singletonList(BauSystem.MESSAGE.parse(permissionString(permission), p));
|
||||||
} else {
|
} else {
|
||||||
lore.add(BauSystem.MESSAGE.parse("NO_PERMISSION", p));
|
lore.add(BauSystem.MESSAGE.parse(permissionString(permission), p));
|
||||||
}
|
}
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
}
|
}
|
||||||
itemStack.setItemMeta(meta);
|
itemStack.setItemMeta(meta);
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String permissionString(Permission permission) {
|
||||||
|
switch (permission) {
|
||||||
|
case OWNER:
|
||||||
|
return "GUI_NO_OWNER";
|
||||||
|
case WORLD:
|
||||||
|
return "GUI_NO_WORLD";
|
||||||
|
case WORLDEDIT:
|
||||||
|
return "GUI_NO_WORLDEDIT";
|
||||||
|
default:
|
||||||
|
return "GUI_NO_MEMBER";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,15 +20,16 @@
|
|||||||
package de.steamwar.bausystem.features.gui;
|
package de.steamwar.bausystem.features.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.gui.editor.BauGuiEditor;
|
import de.steamwar.bausystem.features.gui.editor.BauGuiEditor;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.COMMAND)
|
||||||
public class BauGUICommand extends SWCommand {
|
public class BauGUICommand extends SWCommand {
|
||||||
|
|
||||||
public BauGUICommand() {
|
protected BauGUICommand() {
|
||||||
super("gui", "baugui", "g");
|
super("gui", "baugui", "g");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,10 @@ package de.steamwar.bausystem.features.gui;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -32,7 +33,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.BAU_GUI_ITEM)
|
||||||
public class BauGuiBauGuiItem extends BauGuiItem {
|
public class BauGuiBauGuiItem extends BauGuiItem {
|
||||||
|
|
||||||
public BauGuiBauGuiItem() {
|
public BauGuiBauGuiItem() {
|
||||||
|
@ -19,13 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.gui;
|
package de.steamwar.bausystem.features.gui;
|
||||||
|
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
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.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.LISTENER)
|
||||||
public class BauGuiListener implements Listener {
|
public class BauGuiListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -21,10 +21,11 @@ package de.steamwar.bausystem.features.gui.editor;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.gui.BauGUI;
|
import de.steamwar.bausystem.features.gui.BauGUI;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -39,14 +40,13 @@ import org.bukkit.event.inventory.InventoryDragEvent;
|
|||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryView;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.LISTENER)
|
||||||
public class BauGuiEditor implements Listener {
|
public class BauGuiEditor implements Listener {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -73,7 +73,6 @@ public class BauGuiEditor implements Listener {
|
|||||||
inv.setItem(mapping.getSize() + 5, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH", p), Arrays.asList(BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH_LORE", p)), false, clickType -> {
|
inv.setItem(mapping.getSize() + 5, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH", p), Arrays.asList(BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH_LORE", p)), false, clickType -> {
|
||||||
}).getItemStack());
|
}).getItemStack());
|
||||||
inv.setItem(mapping.getSize() + 6, new SWItem(Material.SCUTE, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_MORE", p)).getItemStack());
|
inv.setItem(mapping.getSize() + 6, new SWItem(Material.SCUTE, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_MORE", p)).getItemStack());
|
||||||
inv.setItem(mapping.getSize() + 8, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_CLOSE", p)).getItemStack());
|
|
||||||
|
|
||||||
p.openInventory(inv);
|
p.openInventory(inv);
|
||||||
p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor);
|
p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor);
|
||||||
@ -157,10 +156,6 @@ public class BauGuiEditor implements Listener {
|
|||||||
});
|
});
|
||||||
inv.open();
|
inv.open();
|
||||||
break;
|
break;
|
||||||
case 8:
|
|
||||||
saveMapping(p);
|
|
||||||
BauGUI.openBauGui(p);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,17 +189,14 @@ public class BauGuiEditor implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveMapping(Player p) {
|
private void saveMapping(Player p) {
|
||||||
saveMapping(p.getOpenInventory(), BauGuiMapping.getGuiMapping(p));
|
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
|
||||||
}
|
|
||||||
|
|
||||||
private void saveMapping(InventoryView view, BauGuiMapping mapping) {
|
|
||||||
if (mapping.isSaved()) {
|
if (mapping.isSaved()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HashMap<Integer, Integer> newMapping = new HashMap<>();
|
HashMap<Integer, Integer> newMapping = new HashMap<>();
|
||||||
|
|
||||||
for (int i = 0; i < view.getTopInventory().getContents().length; i++) {
|
for (int i = 0; i < p.getOpenInventory().getTopInventory().getContents().length; i++) {
|
||||||
ItemStack itemStack = view.getTopInventory().getContents()[i];
|
ItemStack itemStack = p.getOpenInventory().getTopInventory().getContents()[i];
|
||||||
if (itemStack == null || itemStack.getType() == Material.AIR || i >= mapping.getSize()) continue;
|
if (itemStack == null || itemStack.getType() == Material.AIR || i >= mapping.getSize()) continue;
|
||||||
newMapping.put(getId(itemStack), i);
|
newMapping.put(getId(itemStack), i);
|
||||||
}
|
}
|
||||||
@ -227,7 +219,7 @@ public class BauGuiEditor implements Listener {
|
|||||||
|
|
||||||
Player p = (Player) event.getPlayer();
|
Player p = (Player) event.getPlayer();
|
||||||
|
|
||||||
saveMapping(event.getView(), BauGuiMapping.getGuiMapping(p));
|
saveMapping(p);
|
||||||
open_Edits.remove(p);
|
open_Edits.remove(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,16 @@ package de.steamwar.bausystem.features.gui.editor;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.BAU_GUI_ITEM)
|
||||||
public class BauGuiEditorGuiItem extends BauGuiItem {
|
public class BauGuiEditorGuiItem extends BauGuiItem {
|
||||||
|
|
||||||
public BauGuiEditorGuiItem() {
|
public BauGuiEditorGuiItem() {
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.bausystem.features.hotbar;
|
package de.steamwar.bausystem.features.hotbar;
|
||||||
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
import de.steamwar.core.Core;
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -31,18 +30,14 @@ import yapion.parser.YAPIONParser;
|
|||||||
import yapion.serializing.YAPIONDeserializer;
|
import yapion.serializing.YAPIONDeserializer;
|
||||||
import yapion.serializing.YAPIONSerializer;
|
import yapion.serializing.YAPIONSerializer;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class DefaultHotbar {
|
public class DefaultHotbar {
|
||||||
|
|
||||||
private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.inventory.ItemStack)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(WorldEdit Wand)lore{@type(java.util.ArrayList)values[Left click: select pos #1,Right click: select pos #2]}}},{@type(org.bukkit.inventory.ItemStack)v(2230)type(COMPASS)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(Navigation Wand)lore{@type(java.util.ArrayList)values[Left click: jump to location,Right click: pass through walls]}}},null,null,null,null,null,null,{@type(org.bukkit.inventory.ItemStack)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(§eBau GUI)}},null,null,{@type(org.bukkit.inventory.ItemStack)v(3117)type(ELYTRA)},null]}").getArray("");
|
private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.inventory.ItemStack)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(WorldEdit Wand)lore{@type(java.util.ArrayList)values[Left click: select pos #1,Right click: select pos #2]}}},{@type(org.bukkit.inventory.ItemStack)v(2230)type(COMPASS)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(Navigation Wand)lore{@type(java.util.ArrayList)values[Left click: jump to location,Right click: pass through walls]}}},null,null,null,null,null,null,{@type(org.bukkit.inventory.ItemStack)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(§eBau GUI)}}]}").getArray("");
|
||||||
|
|
||||||
public void updateHotbar(Player p) {
|
public void updateHotbar(Player p) {
|
||||||
ItemStack[] hotbar = new ItemStack[13];
|
ItemStack[] hotbar = new ItemStack[9];
|
||||||
System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9);
|
System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9);
|
||||||
System.arraycopy(p.getInventory().getArmorContents(), 0, hotbar, 9, 4);
|
|
||||||
YAPIONArray yapionArray = new YAPIONArray();
|
YAPIONArray yapionArray = new YAPIONArray();
|
||||||
for (ItemStack itemStack : hotbar) {
|
for (ItemStack itemStack : hotbar) {
|
||||||
if (itemStack != null) {
|
if (itemStack != null) {
|
||||||
@ -51,39 +46,27 @@ public class DefaultHotbar {
|
|||||||
yapionArray.add(new YAPIONValue<>(null));
|
yapionArray.add(new YAPIONValue<>(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Config.getInstance().get(p).add("hotbar-" + Core.getVersion(), yapionArray);
|
Config.getInstance().get(p).add("hotbar", yapionArray);
|
||||||
Config.getInstance().save(p);
|
Config.getInstance().save(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHotbar(Player p) {
|
public void setHotbar(Player p) {
|
||||||
ItemStack[] hotbar = getItems(p);
|
ItemStack[] hotbar = getItems(p);
|
||||||
ItemStack[] inv = p.getInventory().getContents();
|
ItemStack[] inv = p.getInventory().getContents();
|
||||||
ItemStack[] armor = p.getInventory().getArmorContents();
|
|
||||||
System.arraycopy(hotbar, 0, inv, 0, 9);
|
System.arraycopy(hotbar, 0, inv, 0, 9);
|
||||||
System.arraycopy(hotbar, 9, armor, 0, 4);
|
|
||||||
p.getInventory().setContents(inv);
|
p.getInventory().setContents(inv);
|
||||||
p.getInventory().setArmorContents(armor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getItems(Player p) {
|
public ItemStack[] getItems(Player p) {
|
||||||
Config.getInstance().get(p).remap("hotbar", "hotbar-19");
|
YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar", defaultHotbar());
|
||||||
YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar-" + Core.getVersion(), defaultHotbar());
|
ItemStack[] hotbar = new ItemStack[9];
|
||||||
ItemStack[] hotbar = new ItemStack[13];
|
|
||||||
Set<Integer> invalid = new HashSet<>();
|
|
||||||
yapionArray.forEach((integer, yapionAnyType) -> {
|
yapionArray.forEach((integer, yapionAnyType) -> {
|
||||||
if (yapionAnyType instanceof YAPIONValue) {
|
if (yapionAnyType instanceof YAPIONValue) {
|
||||||
hotbar[integer] = null;
|
hotbar[integer] = null;
|
||||||
} else {
|
} else {
|
||||||
try {
|
hotbar[integer] = (ItemStack) YAPIONDeserializer.deserialize((YAPIONObject) yapionAnyType);
|
||||||
hotbar[integer] = YAPIONDeserializer.deserialize((YAPIONObject) yapionAnyType);
|
|
||||||
} catch (Exception e) {
|
|
||||||
invalid.add(integer);
|
|
||||||
hotbar[integer] = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
invalid.forEach(i -> yapionArray.set(i, new YAPIONValue<>(null)));
|
|
||||||
if (!invalid.isEmpty()) Config.getInstance().save(p);
|
|
||||||
return hotbar;
|
return hotbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,22 +20,23 @@
|
|||||||
package de.steamwar.bausystem.features.hotbar;
|
package de.steamwar.bausystem.features.hotbar;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.COMMAND)
|
||||||
public class HotbarCommand extends SWCommand {
|
public class HotbarCommand extends SWCommand {
|
||||||
|
|
||||||
public HotbarCommand() {
|
protected HotbarCommand() {
|
||||||
super("hotbar", "hb");
|
super("hotbar", "hb");
|
||||||
addDefaultHelpMessage("HOTBAR_HELP_GENERIC");
|
addDefaultHelpMessage("HOTBAR_HELP_GENERIC");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "load", description = "HOTBAR_HELP_LOAD")
|
@Register(value = "load", description = "HOTBAR_HELP_LOAD")
|
||||||
public void loadHotbar(@Validator Player p) {
|
public void loadHotbar(Player p) {
|
||||||
DefaultHotbar.setHotbar(p);
|
DefaultHotbar.setHotbar(p);
|
||||||
BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
|
BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
|
||||||
}
|
}
|
||||||
@ -48,7 +49,7 @@ public class HotbarCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register(value = "show", description = "HOTBAR_HELP_SHOW")
|
@Register(value = "show", description = "HOTBAR_HELP_SHOW")
|
||||||
public void showHotbar(Player p) {
|
public void showHotbar(Player p) {
|
||||||
SWInventory inv = new SWInventory(p, 18, BauSystem.MESSAGE.parse("HOTBAR_INVENTORY", p));
|
SWInventory inv = new SWInventory(p, 9, BauSystem.MESSAGE.parse("HOTBAR_INVENTORY", p));
|
||||||
ItemStack[] hotbar = DefaultHotbar.getItems(p);
|
ItemStack[] hotbar = DefaultHotbar.getItems(p);
|
||||||
for (int i = 0; i < hotbar.length; i++) {
|
for (int i = 0; i < hotbar.length; i++) {
|
||||||
if (hotbar[i] == null) continue;
|
if (hotbar[i] == null) continue;
|
||||||
|
@ -19,20 +19,19 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.hotbar;
|
package de.steamwar.bausystem.features.hotbar;
|
||||||
|
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.LISTENER)
|
||||||
public class HotbarListener implements Listener {
|
public class HotbarListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (allNull(event.getPlayer().getInventory().getContents())) {
|
||||||
if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) {
|
|
||||||
DefaultHotbar.setHotbar(event.getPlayer());
|
DefaultHotbar.setHotbar(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
package de.steamwar.bausystem.features.inventoryfiller;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.linkage.LinkedInstance;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class InventoryFillBauGuiItem extends BauGuiItem {
|
|
||||||
public InventoryFillBauGuiItem() {
|
|
||||||
super(34);
|
|
||||||
}
|
|
||||||
|
|
||||||
@LinkedInstance
|
|
||||||
public InventoryFillerCommand command;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Permission permission() {
|
|
||||||
return Permission.MEMBER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getItem(Player player) {
|
|
||||||
String loreKey = Config.getInstance().get(player).getPlainValueOrDefault("inventoryfill", false) ? "OTHER_ITEMS_INVENTORY_FILL_LORE_ACTIVE" : "OTHER_ITEMS_INVENTORY_FILL_LORE_INACTIVE";
|
|
||||||
return new SWItem(Material.HOPPER, BauSystem.MESSAGE.parse("OTHER_ITEMS_INVENTORY_FILL_NAME", player), Collections.singletonList(BauSystem.MESSAGE.parse(loreKey, player)), false, clickType -> {}).getItemStack();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean click(ClickType click, Player p) {
|
|
||||||
command.toggle(p);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.inventoryfiller;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.Container;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
|
||||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class InventoryFiller implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
|
||||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return;
|
|
||||||
if (!event.getPlayer().isSneaking()) return;
|
|
||||||
Block block = event.getPlayer().getTargetBlockExact(5);
|
|
||||||
if (block == null) return;
|
|
||||||
if (!(block.getState() instanceof Container)) return;
|
|
||||||
Container container = (Container) block.getState();
|
|
||||||
Inventory inventory = container.getInventory();
|
|
||||||
ItemStack itemStack = event.getItemDrop().getItemStack().clone();
|
|
||||||
itemStack.setAmount(itemStack.getType().getMaxStackSize());
|
|
||||||
event.setCancelled(true);
|
|
||||||
for (int i = 0; i < inventory.getSize(); i++) {
|
|
||||||
inventory.setItem(i, itemStack);
|
|
||||||
}
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("CHESTFILLER_FILLED", event.getPlayer(), ChatMessageType.ACTION_BAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For MacOS user: https://www.curseforge.com/minecraft/mc-mods/shift-scroll-fix
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
|
||||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
|
||||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return;
|
|
||||||
if (!event.getPlayer().isSneaking()) return;
|
|
||||||
ItemStack itemStack = event.getPlayer().getInventory().getItemInMainHand();
|
|
||||||
if (itemStack.getType() == Material.AIR) return;
|
|
||||||
Block block = event.getPlayer().getTargetBlockExact(5);
|
|
||||||
if (block == null) return;
|
|
||||||
if (!(block.getState() instanceof Container)) return;
|
|
||||||
Container container = (Container) block.getState();
|
|
||||||
Inventory inventory = container.getInventory();
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
int upperBound = event.getPreviousSlot() + 4;
|
|
||||||
if (upperBound > 8) upperBound -= 8;
|
|
||||||
int lowerBound = event.getPreviousSlot() - 5;
|
|
||||||
if (lowerBound < 0) lowerBound += 8;
|
|
||||||
|
|
||||||
int direction = 0;
|
|
||||||
if (event.getPreviousSlot() != 0 && (event.getNewSlot() > event.getPreviousSlot() || (upperBound < event.getPreviousSlot() && event.getNewSlot() < upperBound))) {
|
|
||||||
direction = 1;
|
|
||||||
} else if (event.getPreviousSlot() == 0 && event.getNewSlot() > upperBound) {
|
|
||||||
direction = -1;
|
|
||||||
} else if (event.getNewSlot() < event.getPreviousSlot() || (lowerBound > event.getPreviousSlot() && event.getNewSlot() >= lowerBound)) {
|
|
||||||
direction = -1;
|
|
||||||
} else if (event.getPreviousSlot() == 0) {
|
|
||||||
direction = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
int emptySlot = -1;
|
|
||||||
int filledSlot = -1;
|
|
||||||
for (int i = 0; i < inventory.getSize(); i++) {
|
|
||||||
ItemStack current = inventory.getItem(i);
|
|
||||||
if (current == null) {
|
|
||||||
if (emptySlot == -1) emptySlot = i;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (current.getType() == itemStack.getType()) {
|
|
||||||
count += current.getAmount();
|
|
||||||
int emptyAmount = itemStack.getType().getMaxStackSize() - current.getAmount();
|
|
||||||
if (direction == -1) filledSlot = Math.max(filledSlot, i);
|
|
||||||
if (emptyAmount > 0) filledSlot = Math.min(i, filledSlot);
|
|
||||||
if (emptyAmount > 0 && filledSlot == -1) filledSlot = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int slotToUse = direction == -1 ? filledSlot : (filledSlot == -1 ? emptySlot : filledSlot);
|
|
||||||
if (slotToUse == -1) return;
|
|
||||||
|
|
||||||
ItemStack current = inventory.getItem(slotToUse);
|
|
||||||
if (current == null) {
|
|
||||||
ItemStack now = itemStack.clone();
|
|
||||||
now.setAmount(1);
|
|
||||||
inventory.setItem(slotToUse, now);
|
|
||||||
} else {
|
|
||||||
current.setAmount(current.getAmount() + direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("CHESTFILLER_COUNT", event.getPlayer(), ChatMessageType.ACTION_BAR, itemStack.getType(), count + direction);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package de.steamwar.bausystem.features.inventoryfiller;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.SWUtils;
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class InventoryFillerCommand extends SWCommand {
|
|
||||||
|
|
||||||
public InventoryFillerCommand() {
|
|
||||||
super("inventoryfill");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(description = {"INVENTORY_FILL_HELP", "INVENTORY_FILL_INFO"})
|
|
||||||
public void toggle(Player player) {
|
|
||||||
boolean inventoryFill = Config.getInstance().get(player).getPlainValueOrDefault("inventoryfill", false);
|
|
||||||
Config.getInstance().get(player).put("inventoryfill", !inventoryFill);
|
|
||||||
if (!inventoryFill) {
|
|
||||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("INVENTORY_FILL_ENABLE", player));
|
|
||||||
BauSystem.MESSAGE.send("INVENTORY_FILL_INFO", player);
|
|
||||||
}else {
|
|
||||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("INVENTORY_FILL_DISABLE", player));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,115 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.killchecker;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
|
||||||
import de.steamwar.bausystem.utils.bossbar.BossBarService;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.linkage.LinkedInstance;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class KillcheckerCommand extends SWCommand implements Listener {
|
|
||||||
|
|
||||||
private Map<Region, KillcheckerVisualizer> visualizers = new HashMap<>();
|
|
||||||
|
|
||||||
@LinkedInstance
|
|
||||||
public BossBarService bossBarService;
|
|
||||||
|
|
||||||
public KillcheckerCommand() {
|
|
||||||
super("killchecker");
|
|
||||||
addDefaultHelpMessage("KILLCHECKER_INFO");
|
|
||||||
addDefaultHelpMessage("KILLCHECKER_INFO2");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE")
|
|
||||||
public void genericCommand(@Validator Player player, @OptionalValue("-outline") @StaticValue(value = {"-area", "-outline"}, allowISE = true) boolean onlyOutline) {
|
|
||||||
Region region = Region.getRegion(player.getLocation());
|
|
||||||
KillcheckerVisualizer killcheckerVisualizer = visualizers.computeIfAbsent(region, region1 -> new KillcheckerVisualizer(region1, bossBarService));
|
|
||||||
killcheckerVisualizer.recalc();
|
|
||||||
killcheckerVisualizer.show(player, onlyOutline);
|
|
||||||
BauSystem.MESSAGE.send("KILLCHECKER_ENABLE", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "disable", description = "KILLCHECKER_HELP_DISABLE")
|
|
||||||
public void disableCommand(Player player) {
|
|
||||||
Region region = Region.getRegion(player.getLocation());
|
|
||||||
KillcheckerVisualizer killcheckerVisualizer = visualizers.get(region);
|
|
||||||
if (killcheckerVisualizer != null) {
|
|
||||||
if (killcheckerVisualizer.hide(player)) {
|
|
||||||
visualizers.remove(region);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BauSystem.MESSAGE.send("KILLCHECKER_DISABLE", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
|
||||||
event.getNewSpectator().forEach(this::hide);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
hide(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void hide(Player player) {
|
|
||||||
new HashSet<>(visualizers.entrySet()).forEach(regionKillcheckerVisualizerEntry -> {
|
|
||||||
if (regionKillcheckerVisualizerEntry.getValue().hide(player)) {
|
|
||||||
visualizers.remove(regionKillcheckerVisualizerEntry.getKey());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void recalc(Block block) {
|
|
||||||
Region region = Region.getRegion(block.getLocation());
|
|
||||||
KillcheckerVisualizer killcheckerVisualizer = visualizers.get(region);
|
|
||||||
if (killcheckerVisualizer != null) {
|
|
||||||
killcheckerVisualizer.recalc();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
|
||||||
recalc(event.getBlock());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
recalc(event.getBlock());
|
|
||||||
}, 1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,390 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.killchecker;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.region.Point;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
|
||||||
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
|
|
||||||
import de.steamwar.bausystem.utils.bossbar.BossBarService;
|
|
||||||
import de.steamwar.entity.REntity;
|
|
||||||
import de.steamwar.entity.REntityServer;
|
|
||||||
import de.steamwar.entity.RFallingBlockEntity;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.boss.BarColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class KillcheckerVisualizer {
|
|
||||||
|
|
||||||
private static final Material[] MATERIALS = new Material[]{
|
|
||||||
Material.LIME_STAINED_GLASS,
|
|
||||||
Material.LIME_CONCRETE,
|
|
||||||
Material.GREEN_STAINED_GLASS,
|
|
||||||
Material.GREEN_CONCRETE,
|
|
||||||
Material.YELLOW_STAINED_GLASS,
|
|
||||||
Material.YELLOW_CONCRETE,
|
|
||||||
Material.ORANGE_STAINED_GLASS,
|
|
||||||
Material.ORANGE_CONCRETE,
|
|
||||||
Material.RED_STAINED_GLASS,
|
|
||||||
Material.RED_CONCRETE,
|
|
||||||
Material.PURPLE_STAINED_GLASS,
|
|
||||||
Material.PURPLE_CONCRETE,
|
|
||||||
Material.BLACK_STAINED_GLASS,
|
|
||||||
Material.BLACK_CONCRETE,
|
|
||||||
};
|
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
|
||||||
|
|
||||||
private static final double SURROUND = 4.5;
|
|
||||||
|
|
||||||
private final Point minPoint;
|
|
||||||
private final Point maxPoint;
|
|
||||||
|
|
||||||
private final int yArea;
|
|
||||||
private final int zArea;
|
|
||||||
private final int xArea;
|
|
||||||
|
|
||||||
private final Region region;
|
|
||||||
private final BossBarService bossBarService;
|
|
||||||
|
|
||||||
public KillcheckerVisualizer(Region region, BossBarService bossBarService) {
|
|
||||||
this.region = region;
|
|
||||||
this.minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL);
|
|
||||||
this.maxPoint = region.getMaxPoint(RegionType.BUILD, RegionExtensionType.NORMAL);
|
|
||||||
|
|
||||||
yArea = (maxPoint.getX() - minPoint.getX()) * (maxPoint.getZ() - minPoint.getZ());
|
|
||||||
zArea = (maxPoint.getX() - minPoint.getX()) * (maxPoint.getY() - minPoint.getY());
|
|
||||||
xArea = (maxPoint.getY() - minPoint.getY()) * (maxPoint.getZ() - minPoint.getZ());
|
|
||||||
|
|
||||||
this.bossBarService = bossBarService;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final REntityServer outline = new REntityServer();
|
|
||||||
private final REntityServer inner = new REntityServer();
|
|
||||||
|
|
||||||
private final Map<Point, Integer> killCount = new HashMap<>();
|
|
||||||
private final Set<Point> outlinePointsCache = new HashSet<>();
|
|
||||||
private final Map<Point, REntity> rEntities = new HashMap<>();
|
|
||||||
|
|
||||||
private double percent = 0;
|
|
||||||
private int kills = 0;
|
|
||||||
private int cannonCount = 0;
|
|
||||||
|
|
||||||
public void recalc() {
|
|
||||||
Set<Cuboid> cuboids = new HashSet<>();
|
|
||||||
Set<Point> points = new HashSet<>();
|
|
||||||
for (int x = minPoint.getX() + 1; x < maxPoint.getX(); x++) {
|
|
||||||
for (int y = minPoint.getY(); y < maxPoint.getY(); y++) {
|
|
||||||
for (int z = minPoint.getZ() + 1; z < maxPoint.getZ(); z++) {
|
|
||||||
if (points.contains(new Point(x, y, z))) continue;
|
|
||||||
Block block = WORLD.getBlockAt(x, y, z);
|
|
||||||
if (block.getType().isAir()) continue;
|
|
||||||
String name = block.getType().name();
|
|
||||||
if (!name.endsWith("_WOOL") && !name.endsWith("_STAINED_GLASS") && !name.endsWith("_CONCRETE") && !name.endsWith("_TERRACOTTA")) continue;
|
|
||||||
if (name.equals("_GLAZED_TERRACOTTA")) continue;
|
|
||||||
Cuboid cuboid = create(block.getType(), x, y, z);
|
|
||||||
cuboids.add(cuboid);
|
|
||||||
for (int dx = (int) cuboid.getX(); dx <= cuboid.getDx(); dx++) {
|
|
||||||
for (int dy = (int) cuboid.getY(); dy <= cuboid.getDy(); dy++) {
|
|
||||||
for (int dz = (int) cuboid.getZ(); dz <= cuboid.getDz(); dz++) {
|
|
||||||
points.add(new Point(dx, dy, dz));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cannonCount = cuboids.size();
|
|
||||||
|
|
||||||
Map<Point, Integer> kill = new HashMap<>();
|
|
||||||
int yKills = 0;
|
|
||||||
int yCount = 0;
|
|
||||||
Set<Point> yPoints = new HashSet<>();
|
|
||||||
for (int x = minPoint.getX(); x <= maxPoint.getX(); x++) {
|
|
||||||
for (int z = minPoint.getZ(); z <= maxPoint.getZ(); z++) {
|
|
||||||
Set<Cuboid> cuboidSet = new HashSet<>();
|
|
||||||
for (Cuboid cuboid : cuboids) {
|
|
||||||
if (x >= cuboid.getX() - SURROUND && x < cuboid.getDx() + SURROUND && z >= cuboid.getZ() - SURROUND && z < cuboid.getDz() + SURROUND) {
|
|
||||||
cuboidSet.add(cuboid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cuboidSet.size() > 1) {
|
|
||||||
yCount++;
|
|
||||||
yKills += splitIntoDoubleKills(cuboidSet.size());
|
|
||||||
Point p2 = new Point(x, maxPoint.getY() + 1, z);
|
|
||||||
yPoints.add(p2);
|
|
||||||
kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int xKills = 0;
|
|
||||||
int xCount = 0;
|
|
||||||
Set<Point> xPoints = new HashSet<>();
|
|
||||||
for (int y = minPoint.getY(); y <= maxPoint.getY(); y++) {
|
|
||||||
for (int z = minPoint.getZ(); z <= maxPoint.getZ(); z++) {
|
|
||||||
Set<Cuboid> cuboidSet = new HashSet<>();
|
|
||||||
for (Cuboid cuboid : cuboids) {
|
|
||||||
if (y >= cuboid.getY() - SURROUND && y < cuboid.getDy() + SURROUND && z >= cuboid.getZ() - SURROUND && z < cuboid.getDz() + SURROUND) {
|
|
||||||
cuboidSet.add(cuboid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cuboidSet.size() > 1) {
|
|
||||||
xCount++;
|
|
||||||
xKills += splitIntoDoubleKills(cuboidSet.size());
|
|
||||||
Point p1 = new Point(minPoint.getX() - 1, y, z);
|
|
||||||
xPoints.add(p1);
|
|
||||||
kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size()));
|
|
||||||
Point p2 = new Point(maxPoint.getX() + 1, y, z);
|
|
||||||
xPoints.add(p2);
|
|
||||||
kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int zKills = 0;
|
|
||||||
int zCount = 0;
|
|
||||||
Set<Point> zPoints = new HashSet<>();
|
|
||||||
for (int x = minPoint.getX(); x <= maxPoint.getX(); x++) {
|
|
||||||
for (int y = minPoint.getY(); y <= maxPoint.getY(); y++) {
|
|
||||||
Set<Cuboid> cuboidSet = new HashSet<>();
|
|
||||||
for (Cuboid cuboid : cuboids) {
|
|
||||||
if (x >= cuboid.getX() - SURROUND && x < cuboid.getDx() + SURROUND && y >= cuboid.getY() - SURROUND && y < cuboid.getDy() + SURROUND) {
|
|
||||||
cuboidSet.add(cuboid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cuboidSet.size() > 1) {
|
|
||||||
zCount++;
|
|
||||||
zKills += splitIntoDoubleKills(cuboidSet.size());
|
|
||||||
Point p1 = new Point(x, y, minPoint.getZ() - 1);
|
|
||||||
zPoints.add(p1);
|
|
||||||
kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size()));
|
|
||||||
Point p2 = new Point(x, y, maxPoint.getZ() + 1);
|
|
||||||
zPoints.add(p2);
|
|
||||||
kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Point> outlinePoints = new HashSet<>();
|
|
||||||
yPoints.forEach(point -> {
|
|
||||||
Point p1 = new Point(point.getX() - 1, point.getY(), point.getZ());
|
|
||||||
Point p2 = new Point(point.getX() + 1, point.getY(), point.getZ());
|
|
||||||
Point p3 = new Point(point.getX(), point.getY(), point.getZ() - 1);
|
|
||||||
Point p4 = new Point(point.getX(), point.getY(), point.getZ() + 1);
|
|
||||||
|
|
||||||
Point p5 = new Point(point.getX() - 1, point.getY(), point.getZ() - 1);
|
|
||||||
Point p6 = new Point(point.getX() - 1, point.getY(), point.getZ() + 1);
|
|
||||||
Point p7 = new Point(point.getX() + 1, point.getY(), point.getZ() - 1);
|
|
||||||
Point p8 = new Point(point.getX() + 1, point.getY(), point.getZ() + 1);
|
|
||||||
|
|
||||||
int count = kill.get(point);
|
|
||||||
|
|
||||||
int surrounded = 0;
|
|
||||||
if (kill.getOrDefault(p1, 0) == count) surrounded++;
|
|
||||||
if (kill.getOrDefault(p2, 0) == count) surrounded++;
|
|
||||||
if (kill.getOrDefault(p3, 0) == count) surrounded++;
|
|
||||||
if (kill.getOrDefault(p4, 0) == count) surrounded++;
|
|
||||||
if (surrounded != 4) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p5, 0) != count) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p6, 0) != count) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p7, 0) != count) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p8, 0) != count) outlinePoints.add(point);
|
|
||||||
});
|
|
||||||
xPoints.forEach(point -> {
|
|
||||||
Point p1 = new Point(point.getX(), point.getY() - 1, point.getZ());
|
|
||||||
Point p2 = new Point(point.getX(), point.getY() + 1, point.getZ());
|
|
||||||
Point p3 = new Point(point.getX(), point.getY(), point.getZ() - 1);
|
|
||||||
Point p4 = new Point(point.getX(), point.getY(), point.getZ() + 1);
|
|
||||||
|
|
||||||
Point p5 = new Point(point.getX(), point.getY() - 1, point.getZ() - 1);
|
|
||||||
Point p6 = new Point(point.getX(), point.getY() - 1, point.getZ() + 1);
|
|
||||||
Point p7 = new Point(point.getX(), point.getY() + 1, point.getZ() - 1);
|
|
||||||
Point p8 = new Point(point.getX(), point.getY() + 1, point.getZ() + 1);
|
|
||||||
|
|
||||||
int count = kill.get(point);
|
|
||||||
|
|
||||||
int surrounded = 0;
|
|
||||||
if (kill.getOrDefault(p1, 0) == count) surrounded++;
|
|
||||||
if (kill.getOrDefault(p2, 0) == count) surrounded++;
|
|
||||||
if (kill.getOrDefault(p3, 0) == count) surrounded++;
|
|
||||||
if (kill.getOrDefault(p4, 0) == count) surrounded++;
|
|
||||||
if (surrounded != 4) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p5, 0) != count) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p6, 0) != count) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p7, 0) != count) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p8, 0) != count) outlinePoints.add(point);
|
|
||||||
});
|
|
||||||
zPoints.forEach(point -> {
|
|
||||||
Point p1 = new Point(point.getX() - 1, point.getY(), point.getZ());
|
|
||||||
Point p2 = new Point(point.getX() + 1, point.getY(), point.getZ());
|
|
||||||
Point p3 = new Point(point.getX(), point.getY() - 1, point.getZ());
|
|
||||||
Point p4 = new Point(point.getX(), point.getY() + 1, point.getZ());
|
|
||||||
|
|
||||||
Point p5 = new Point(point.getX() - 1, point.getY() - 1, point.getZ());
|
|
||||||
Point p6 = new Point(point.getX() - 1, point.getY() + 1, point.getZ());
|
|
||||||
Point p7 = new Point(point.getX() + 1, point.getY() - 1, point.getZ());
|
|
||||||
Point p8 = new Point(point.getX() + 1, point.getY() + 1, point.getZ());
|
|
||||||
|
|
||||||
int count = kill.get(point);
|
|
||||||
|
|
||||||
int surrounded = 0;
|
|
||||||
if (kill.getOrDefault(p1, 0) == count) surrounded++;
|
|
||||||
if (kill.getOrDefault(p2, 0) == count) surrounded++;
|
|
||||||
if (kill.getOrDefault(p3, 0) == count) surrounded++;
|
|
||||||
if (kill.getOrDefault(p4, 0) == count) surrounded++;
|
|
||||||
if (surrounded != 4) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p5, 0) != count) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p6, 0) != count) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p7, 0) != count) outlinePoints.add(point);
|
|
||||||
if (kill.getOrDefault(p8, 0) != count) outlinePoints.add(point);
|
|
||||||
});
|
|
||||||
|
|
||||||
double xPercent = zCount / (double) xArea;
|
|
||||||
double yPercent = yCount / (double) yArea;
|
|
||||||
double zPercent = xCount / (double) zArea;
|
|
||||||
percent = (xPercent + yPercent + zPercent) / 3;
|
|
||||||
kills = zKills + yKills + xKills;
|
|
||||||
outline.getPlayers().forEach(this::updateBossBar);
|
|
||||||
|
|
||||||
Set<Point> pointSet = new HashSet<>(killCount.keySet());
|
|
||||||
Set<Point> outlinePointsCacheLast = new HashSet<>(outlinePointsCache);
|
|
||||||
outlinePointsCache.clear();
|
|
||||||
for (Point point : pointSet) {
|
|
||||||
if (!kill.containsKey(point)) {
|
|
||||||
rEntities.get(point).die();
|
|
||||||
rEntities.remove(point);
|
|
||||||
killCount.remove(point);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
kill.forEach((point, count) -> {
|
|
||||||
if (rEntities.containsKey(point)) {
|
|
||||||
if (killCount.get(point) == count && outlinePoints.contains(point) == outlinePointsCacheLast.contains(point)) return;
|
|
||||||
rEntities.get(point).die();
|
|
||||||
}
|
|
||||||
RFallingBlockEntity entity = new RFallingBlockEntity(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0.5, 0, 0.5), MATERIALS[Math.min(count - 1, MATERIALS.length) - 1]);
|
|
||||||
entity.setNoGravity(true);
|
|
||||||
rEntities.put(point, entity);
|
|
||||||
if (outlinePoints.contains(point)) outlinePointsCache.add(point);
|
|
||||||
killCount.put(point, count);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private int splitIntoDoubleKills(int kills) {
|
|
||||||
return kills * (kills - 1) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBossBar(Player player) {
|
|
||||||
BauSystemBossbar bossbar = bossBarService.get(player, region, "killchecker");
|
|
||||||
bossbar.setTitle(BauSystem.MESSAGE.parse("KILLCHECKER_BOSSBAR", player, kills, ((int) (percent * 1000) / 10.0), cannonCount));
|
|
||||||
bossbar.setProgress(Math.min(Math.max(percent, 0), 1));
|
|
||||||
|
|
||||||
if (percent >= 0.35) {
|
|
||||||
bossbar.setColor(BarColor.RED);
|
|
||||||
} else if (percent >= 0.25) {
|
|
||||||
bossbar.setColor(BarColor.PURPLE);
|
|
||||||
} else if (percent >= 0.15) {
|
|
||||||
bossbar.setColor(BarColor.YELLOW);
|
|
||||||
} else {
|
|
||||||
bossbar.setColor(BarColor.GREEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Cuboid create(Material type, int x, int y, int z) {
|
|
||||||
Set<Point> checked = new HashSet<>();
|
|
||||||
Set<Point> points = new HashSet<>();
|
|
||||||
points.add(new Point(x, y, z));
|
|
||||||
while (!points.isEmpty()) {
|
|
||||||
Point point = points.iterator().next();
|
|
||||||
points.remove(point);
|
|
||||||
if (!checked.add(point)) continue;
|
|
||||||
if (point.getX() < minPoint.getX() || point.getX() > maxPoint.getX()) continue;
|
|
||||||
if (point.getY() < minPoint.getY() || point.getY() > maxPoint.getY()) continue;
|
|
||||||
if (point.getZ() < minPoint.getZ() || point.getZ() > maxPoint.getZ()) continue;
|
|
||||||
|
|
||||||
if (WORLD.getBlockAt(point.getX() + 1, point.getY(), point.getZ()).getType() == type) {
|
|
||||||
points.add(new Point(point.getX() + 1, point.getY(), point.getZ()));
|
|
||||||
}
|
|
||||||
if (WORLD.getBlockAt(point.getX(), point.getY() + 1, point.getZ()).getType() == type) {
|
|
||||||
points.add(new Point(point.getX(), point.getY() + 1, point.getZ()));
|
|
||||||
}
|
|
||||||
if (WORLD.getBlockAt(point.getX(), point.getY(), point.getZ() + 1).getType() == type) {
|
|
||||||
points.add(new Point(point.getX(), point.getY(), point.getZ() + 1));
|
|
||||||
}
|
|
||||||
if (WORLD.getBlockAt(point.getX() - 1, point.getY(), point.getZ()).getType() == type) {
|
|
||||||
points.add(new Point(point.getX() - 1, point.getY(), point.getZ()));
|
|
||||||
}
|
|
||||||
if (WORLD.getBlockAt(point.getX(), point.getY() - 1, point.getZ()).getType() == type) {
|
|
||||||
points.add(new Point(point.getX(), point.getY() - 1, point.getZ()));
|
|
||||||
}
|
|
||||||
if (WORLD.getBlockAt(point.getX(), point.getY(), point.getZ() - 1).getType() == type) {
|
|
||||||
points.add(new Point(point.getX(), point.getY(), point.getZ() - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int minX = Integer.MAX_VALUE;
|
|
||||||
int maxX = Integer.MIN_VALUE;
|
|
||||||
int minY = Integer.MAX_VALUE;
|
|
||||||
int maxY = Integer.MIN_VALUE;
|
|
||||||
int minZ = Integer.MAX_VALUE;
|
|
||||||
int maxZ = Integer.MIN_VALUE;
|
|
||||||
for (Point point : checked) {
|
|
||||||
if (point.getX() < minX) minX = point.getX();
|
|
||||||
if (point.getX() > maxX) maxX = point.getX();
|
|
||||||
if (point.getY() < minY) minY = point.getY();
|
|
||||||
if (point.getY() > maxY) maxY = point.getY();
|
|
||||||
if (point.getZ() < minZ) minZ = point.getZ();
|
|
||||||
if (point.getZ() > maxZ) maxZ = point.getZ();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void show(Player player, boolean onlyOutline) {
|
|
||||||
outline.addPlayer(player);
|
|
||||||
if (!onlyOutline) {
|
|
||||||
inner.addPlayer(player);
|
|
||||||
} else {
|
|
||||||
inner.removePlayer(player);
|
|
||||||
}
|
|
||||||
updateBossBar(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hide(Player player) {
|
|
||||||
outline.removePlayer(player);
|
|
||||||
inner.removePlayer(player);
|
|
||||||
bossBarService.remove(player, region, "killchecker");
|
|
||||||
if (outline.getPlayers().isEmpty() && inner.getPlayers().isEmpty()) {
|
|
||||||
outline.close();
|
|
||||||
inner.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of the SteamWar software.
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -20,361 +20,201 @@
|
|||||||
package de.steamwar.bausystem.features.loader;
|
package de.steamwar.bausystem.features.loader;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
import de.steamwar.bausystem.features.loader.elements.LoaderElement;
|
import de.steamwar.bausystem.features.loader.activations.AbstractLoaderActivation;
|
||||||
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
import de.steamwar.bausystem.features.loader.activations.BlockPlaceLoaderActivation;
|
||||||
import de.steamwar.bausystem.features.loader.elements.impl.LoaderTNT;
|
import de.steamwar.bausystem.features.loader.activations.InteractionActivation;
|
||||||
import de.steamwar.bausystem.features.loader.elements.impl.LoaderWait;
|
|
||||||
import de.steamwar.bausystem.shared.EnumDisplay;
|
import de.steamwar.bausystem.shared.EnumDisplay;
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import lombok.AccessLevel;
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.inventory.SWListInv;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
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.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class Loader implements Listener {
|
public class Loader implements Listener {
|
||||||
|
|
||||||
private static final Map<Player, Loader> LOADER_MAP = new HashMap<>();
|
private static final Map<Player, Loader> LOADER_MAP = new HashMap<>();
|
||||||
|
|
||||||
public static Loader getLoader(Player player) {
|
|
||||||
return LOADER_MAP.get(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void newLoader(Player player) {
|
|
||||||
LOADER_MAP.put(player, new Loader(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Player p;
|
private final Player p;
|
||||||
|
private final List<AbstractLoaderActivation> actions = new LinkedList<>();
|
||||||
|
private int ticksBetweenShots = 80;
|
||||||
|
private int ticksBetweenBlocks = 1;
|
||||||
|
private Stage stage;
|
||||||
|
private int lastActivation = -1;
|
||||||
|
private int countdown = 0;
|
||||||
|
|
||||||
@Getter
|
@Getter(AccessLevel.PRIVATE)
|
||||||
private Stage stage = Stage.SETUP;
|
private final BukkitTask task;
|
||||||
private LoaderRecorder recorder;
|
|
||||||
|
|
||||||
private List<LoaderElement> elements = new ArrayList<>();
|
@Getter(AccessLevel.PRIVATE)
|
||||||
private int currentElement = 0;
|
@Setter(AccessLevel.PRIVATE)
|
||||||
private long waitTime = 0;
|
private AbstractLoaderActivation current;
|
||||||
|
|
||||||
public Loader(Player p) {
|
@Getter(AccessLevel.PRIVATE)
|
||||||
|
@Setter(AccessLevel.PRIVATE)
|
||||||
|
private ListIterator<AbstractLoaderActivation> iterator;
|
||||||
|
|
||||||
|
private Loader(Player p) {
|
||||||
this.p = p;
|
this.p = p;
|
||||||
this.recorder = new LoaderRecorder(p, elements);
|
stage = Stage.SETUP;
|
||||||
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
|
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
|
||||||
|
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this::run, 1, 1);
|
||||||
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
|
|
||||||
if (stage != Stage.RUNNING) return;
|
|
||||||
if(!Permission.BUILD.hasPermission(p)) return;
|
|
||||||
if (waitTime > 0) {
|
|
||||||
waitTime--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (currentElement >= elements.size()) {
|
|
||||||
currentElement = 0;
|
|
||||||
if (stage == Stage.SINGLE) {
|
|
||||||
stage = Stage.PAUSE;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (currentElement < elements.size()) {
|
public static Loader getLoader(Player p) {
|
||||||
LoaderElement element = elements.get(currentElement);
|
return LOADER_MAP.getOrDefault(p, null);
|
||||||
currentElement++;
|
|
||||||
element.execute(delay -> waitTime = delay);
|
|
||||||
if (waitTime > 0) {
|
|
||||||
if (element instanceof LoaderTNT) currentElement--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void single() {
|
public static Loader newLoader(Player p) {
|
||||||
if (stage == Stage.END) return;
|
return LOADER_MAP.put(p, new Loader(p));
|
||||||
if (stage == Stage.RUNNING) return;
|
|
||||||
stage = Stage.SINGLE;
|
|
||||||
if (recorder != null) {
|
|
||||||
recorder.stop();
|
|
||||||
recorder = null;
|
|
||||||
}
|
|
||||||
if (elements.isEmpty()) {
|
|
||||||
BauSystem.MESSAGE.send("LOADER_NOTHING_RECORDED", p);
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
if (stage == Stage.END) return;
|
iterator = actions.listIterator();
|
||||||
if (stage == Stage.RUNNING) return;
|
countdown = 0;
|
||||||
|
current = null;
|
||||||
stage = Stage.RUNNING;
|
stage = Stage.RUNNING;
|
||||||
if (recorder != null) {
|
|
||||||
recorder.stop();
|
|
||||||
recorder = null;
|
|
||||||
}
|
|
||||||
if (elements.isEmpty()) {
|
|
||||||
BauSystem.MESSAGE.send("LOADER_NOTHING_RECORDED", p);
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
if (stage == Stage.END) return;
|
if (stage == Stage.RUNNING) {
|
||||||
if (stage == Stage.PAUSE) return;
|
|
||||||
stage = Stage.PAUSE;
|
stage = Stage.PAUSE;
|
||||||
if (recorder != null) {
|
|
||||||
recorder.stop();
|
|
||||||
recorder = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resume() {
|
||||||
|
if (stage == Stage.PAUSE) {
|
||||||
|
stage = Stage.RUNNING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setup() {
|
||||||
|
stage = Stage.SETUP;
|
||||||
|
iterator = null;
|
||||||
|
current = null;
|
||||||
|
countdown = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
stage = Stage.END;
|
stage = Stage.END;
|
||||||
if (recorder != null) {
|
task.cancel();
|
||||||
recorder.stop();
|
LOADER_MAP.remove(p, this);
|
||||||
recorder = null;
|
|
||||||
}
|
|
||||||
elements.clear();
|
|
||||||
LOADER_MAP.remove(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setTicksBetweenShots(int delay) {
|
public void clear() {
|
||||||
if (elements.size() == 0) return false;
|
if (stage == Stage.SETUP) {
|
||||||
LoaderElement loaderElement = elements.get(elements.size() - 1);
|
actions.clear();
|
||||||
if (loaderElement instanceof LoaderWait) {
|
BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR", p);
|
||||||
((LoaderWait) loaderElement).setDelay(delay);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTicksBetweenBlocks(int delay) {
|
|
||||||
for (int i = 0; i < elements.size() - 1; i++) {
|
|
||||||
LoaderElement loaderElement = elements.get(i);
|
|
||||||
if (loaderElement instanceof LoaderWait) {
|
|
||||||
((LoaderWait) loaderElement).setDelay(delay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void gui(SettingsSorting settingsSorting) {
|
|
||||||
List<SWListInv.SWListEntry<LoaderElement>> list = new ArrayList<>();
|
|
||||||
AtomicBoolean allWait = new AtomicBoolean(true);
|
|
||||||
Runnable updateRunnable = () -> {
|
|
||||||
list.clear();
|
|
||||||
for (int i = 0; i < elements.size(); i++) {
|
|
||||||
LoaderElement previous = i > 0 ? elements.get(i - 1) : null;
|
|
||||||
LoaderElement current = elements.get(i);
|
|
||||||
LoaderElement next = i < elements.size() - 1 ? elements.get(i + 1) : null;
|
|
||||||
|
|
||||||
if (!settingsSorting.shouldShow(previous, current, next)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((!(current instanceof LoaderWait))) {
|
|
||||||
allWait.set(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
SWItem item = current.menu(p);
|
|
||||||
if (current instanceof LoaderInteractionElement<?>) {
|
|
||||||
LoaderInteractionElement<?> interactionElement = (LoaderInteractionElement<?>) current;
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
if (item.getItemMeta() != null && item.getItemMeta().getLore() != null) {
|
|
||||||
lore.addAll(item.getItemMeta().getLore());
|
|
||||||
lore.add("§8");
|
|
||||||
}
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, interactionElement.size()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p));
|
|
||||||
item.setLore(lore);
|
|
||||||
} else {
|
} else {
|
||||||
List<String> lore = new ArrayList<>();
|
BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR_HELP", p);
|
||||||
if (item.getItemMeta() != null && item.getItemMeta().getLore() != null) {
|
|
||||||
lore.addAll(item.getItemMeta().getLore());
|
|
||||||
lore.add("§8");
|
|
||||||
}
|
}
|
||||||
lore.add(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p));
|
|
||||||
item.setLore(lore);
|
|
||||||
}
|
}
|
||||||
list.add(new SWListInv.SWListEntry<>(item, current));
|
|
||||||
}
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
allWait.set(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
updateRunnable.run();
|
|
||||||
|
|
||||||
SWListInv<LoaderElement> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {});
|
public void run() {
|
||||||
swListInv.setCallback((clickType, entry) -> entry.click(p, () -> {
|
if (stage == Stage.SETUP && lastActivation >= 0)
|
||||||
updateRunnable.run();
|
lastActivation++;
|
||||||
swListInv.open();
|
|
||||||
}));
|
|
||||||
|
|
||||||
SWItem settingItem = new SWItem(settingsSorting.getMaterial(), "§e" + BauSystem.MESSAGE.parse(settingsSorting.getName(), p), clickType -> {
|
if (stage != Stage.RUNNING) {
|
||||||
if (clickType == ClickType.LEFT) {
|
return;
|
||||||
int index = settingsSorting.ordinal() + 1;
|
|
||||||
if (index >= SettingsSorting.LENGTH) {
|
|
||||||
index = 0;
|
|
||||||
}
|
}
|
||||||
gui(SettingsSorting.values()[index]);
|
|
||||||
} else if (clickType == ClickType.RIGHT) {
|
if (countdown-- > 0) {
|
||||||
int index = settingsSorting.ordinal() - 1;
|
return;
|
||||||
if (index < 0) {
|
|
||||||
index = SettingsSorting.LENGTH - 1;
|
|
||||||
}
|
}
|
||||||
gui(SettingsSorting.values()[index]);
|
|
||||||
|
while (countdown <= 0) {
|
||||||
|
if (!iterator.hasNext()) {
|
||||||
|
countdown = getTicksBetweenShots();
|
||||||
|
iterator = actions.listIterator();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
List<String> strings = new ArrayList<>();
|
current = iterator.next();
|
||||||
for (SettingsSorting setting : SettingsSorting.values()) {
|
|
||||||
if (setting == settingsSorting) {
|
if (current.execute()) {
|
||||||
strings.add("§e> §7" + BauSystem.MESSAGE.parse(setting.getName(), p));
|
countdown = current.delay(this);
|
||||||
} else {
|
} else {
|
||||||
strings.add("§8> §7" + BauSystem.MESSAGE.parse(setting.getName(), p));
|
countdown = 1;
|
||||||
|
iterator.previous();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settingItem.setLore(strings);
|
|
||||||
swListInv.setItem(48, settingItem);
|
|
||||||
|
|
||||||
if (allWait.get()) {
|
public void undo() {
|
||||||
SWItem setWait = new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_ALL", p), clickType -> {
|
if (actions.isEmpty() || stage != Stage.SETUP) {
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), "");
|
return;
|
||||||
swAnvilInv.setCallback(s -> {
|
|
||||||
try {
|
|
||||||
long delay = Math.max(Long.parseLong(s), 0);
|
|
||||||
list.forEach(loaderElementSWListEntry -> {
|
|
||||||
((LoaderWait) loaderElementSWListEntry.getObject()).setDelay(delay);
|
|
||||||
});
|
|
||||||
} catch (NumberFormatException ignored) {
|
|
||||||
}
|
}
|
||||||
gui(settingsSorting);
|
actions.remove(actions.size() - 1);
|
||||||
});
|
}
|
||||||
swAnvilInv.open();
|
|
||||||
});
|
@EventHandler
|
||||||
swListInv.setItem(50, setWait);
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
} else {
|
if (event.getPlayer() != p) {
|
||||||
swListInv.setItem(50, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8"));
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stage != Stage.SETUP) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getBlock().getType() != Material.TNT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
actions.add(new BlockPlaceLoaderActivation(p, event.getBlock().getLocation(), Material.TNT));
|
||||||
|
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("LOADER_MESSAGE_TNT", p, actions.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
if (event.getPlayer() != p) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stage != Stage.SETUP) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL)
|
||||||
|
return;
|
||||||
|
if (event.getClickedBlock().getType() == Material.OBSERVER)
|
||||||
|
return;
|
||||||
|
LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock());
|
||||||
|
if (button != LoaderButton.INVALID) {
|
||||||
|
actions.add(InteractionActivation.construct(p, event.getClickedBlock().getLocation(), this));
|
||||||
|
lastActivation = 0;
|
||||||
|
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", p, BauSystem.MESSAGE.parse(button.getName(), p), actions.size()));
|
||||||
}
|
}
|
||||||
swListInv.open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
if (event.getPlayer() != p) return;
|
if (event.getPlayer() != p) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProgress() {
|
|
||||||
return Math.max(currentElement, 1) + "§8/§7" + elements.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum SettingsSorting {
|
|
||||||
ALL {
|
|
||||||
@Override
|
|
||||||
public Material getMaterial() {
|
|
||||||
return Material.STRUCTURE_VOID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "LOADER_GUI_SHOW_ALL";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
WAIT {
|
|
||||||
@Override
|
|
||||||
public Material getMaterial() {
|
|
||||||
return Material.CLOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "LOADER_GUI_SHOW_WAITS";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
|
|
||||||
return current instanceof LoaderWait;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
WAIT_BETWEEN_TNT {
|
|
||||||
@Override
|
|
||||||
public Material getMaterial() {
|
|
||||||
return Material.REDSTONE_BLOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "LOADER_GUI_SHOW_WAITS_BETWEEN_TNT";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
|
|
||||||
return previous instanceof LoaderTNT && current instanceof LoaderWait && next instanceof LoaderTNT;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
INTERACTIONS {
|
|
||||||
@Override
|
|
||||||
public Material getMaterial() {
|
|
||||||
return Material.REPEATER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "LOADER_GUI_SHOW_INTERACTIONS";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
|
|
||||||
return current instanceof LoaderInteractionElement && !(current instanceof LoaderTNT);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
TNT {
|
|
||||||
@Override
|
|
||||||
public Material getMaterial() {
|
|
||||||
return Material.TNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "LOADER_GUI_SHOW_TNT";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
|
|
||||||
return current instanceof LoaderTNT;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
;
|
|
||||||
|
|
||||||
public static int LENGTH = SettingsSorting.values().length;
|
|
||||||
|
|
||||||
public abstract Material getMaterial();
|
|
||||||
public abstract String getName();
|
|
||||||
public abstract boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum Stage implements EnumDisplay {
|
public enum Stage implements EnumDisplay {
|
||||||
SETUP("LOADER_SETUP"),
|
SETUP("LOADER_SETUP"),
|
||||||
RUNNING("LOADER_RUNNING"),
|
RUNNING("LOADER_RUNNING"),
|
||||||
SINGLE("LOADER_SINGLE"),
|
|
||||||
PAUSE("LOADER_PAUSE"),
|
PAUSE("LOADER_PAUSE"),
|
||||||
END("LOADER_END");
|
END("LOADER_END");
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final String chatValue;
|
private String chatValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.loader;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||||
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
|
import de.steamwar.inventory.SWInventory;
|
||||||
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Linked(LinkageType.BAU_GUI_ITEM)
|
||||||
|
public class LoaderBauGuiItem extends BauGuiItem {
|
||||||
|
|
||||||
|
public LoaderBauGuiItem() {
|
||||||
|
super(9);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem(Player player) {
|
||||||
|
return new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("LOADER_GUI_NAME", player)).getItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean click(ClickType click, Player p) {
|
||||||
|
p.closeInventory();
|
||||||
|
openLoaderGui(p);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openLoaderGui(Player p) {
|
||||||
|
SWInventory inv = new SWInventory(p, 9, BauSystem.MESSAGE.parse("LOADER_GUI_NAME", p));
|
||||||
|
if (Loader.getLoader(p) == null) {
|
||||||
|
inv.setItem(4, new SWItem(Material.SCUTE, BauSystem.MESSAGE.parse("LOADER_GUI_NEW", p), clickType -> {
|
||||||
|
p.closeInventory();
|
||||||
|
p.performCommand("loader setup");
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
Loader loader = Loader.getLoader(p);
|
||||||
|
if (loader.getStage() != Loader.Stage.RUNNING) {
|
||||||
|
inv.setItem(0, new SWItem(Material.GREEN_DYE, BauSystem.MESSAGE.parse("LOADER_GUI_START", p), clickType -> {
|
||||||
|
p.closeInventory();
|
||||||
|
p.performCommand("loader start");
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
inv.setItem(0, new SWItem(Material.RED_DYE, BauSystem.MESSAGE.parse("LOADER_GUI_PAUSE", p), clickType -> {
|
||||||
|
p.closeInventory();
|
||||||
|
p.performCommand("loader pause");
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
inv.setItem(2, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_UNDO", p), clickType -> {
|
||||||
|
p.closeInventory();
|
||||||
|
p.performCommand("loader undo");
|
||||||
|
}));
|
||||||
|
inv.setItem(4, new SWItem(Material.COMPASS, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT", p), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_LORE", p, loader.getTicksBetweenShots())), false, clickType -> {
|
||||||
|
p.closeInventory();
|
||||||
|
SWAnvilInv anvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_TITLE", p));
|
||||||
|
anvilInv.setItem(Material.CLOCK);
|
||||||
|
anvilInv.setCallback(s -> p.performCommand("loader delay " + s));
|
||||||
|
anvilInv.open();
|
||||||
|
}));
|
||||||
|
inv.setItem(6, new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_GUI_SPEED", p), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_SPEED_LORE", p, loader.getTicksBetweenBlocks())), false, clickType -> {
|
||||||
|
p.closeInventory();
|
||||||
|
SWAnvilInv anvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SPEED_TITLE", p));
|
||||||
|
anvilInv.setItem(Material.CLOCK);
|
||||||
|
anvilInv.setCallback(s -> p.performCommand("loader speed " + s));
|
||||||
|
anvilInv.open();
|
||||||
|
}));
|
||||||
|
inv.setItem(8, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_STOP", p), clickType -> {
|
||||||
|
p.closeInventory();
|
||||||
|
p.performCommand("loader stop");
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
inv.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Permission permission() {
|
||||||
|
return Permission.WORLD;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.loader;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum LoaderButton {
|
||||||
|
SWITCH(0, true, "LOADER_BUTTON_SWITCH"),
|
||||||
|
WOOD_BUTTON(30, "LOADER_BUTTON_WOOD_BUTTON"),
|
||||||
|
STONE_BUTTON(20, "LOADER_BUTTON_STONE_BUTTON"),
|
||||||
|
PRESSURE_PLATE(30, "LOADER_BUTTON_PRESSURE_PLATE"),
|
||||||
|
WEIGHTED_PRESSURE_PLATE(20, "LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE"),
|
||||||
|
TRIPWIRE(30, "LOADER_BUTTON_TRIPWIRE"),
|
||||||
|
NOTEBLOCK(1, "LOADER_BUTTON_NOTEBLOCK"),
|
||||||
|
DAYLIGHTSENSOR(0, true, "LOADER_BUTTON_DAYLIGHTSENSOR"),
|
||||||
|
INVALID(-1, "LOADER_BUTTON_INVALID");
|
||||||
|
|
||||||
|
private final int time;
|
||||||
|
private boolean toggle;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public static LoaderButton fromBlock(Block block) {
|
||||||
|
switch (block.getType()) {
|
||||||
|
case LEVER:
|
||||||
|
return LoaderButton.SWITCH;
|
||||||
|
case ACACIA_BUTTON:
|
||||||
|
case BIRCH_BUTTON:
|
||||||
|
case DARK_OAK_BUTTON:
|
||||||
|
case JUNGLE_BUTTON:
|
||||||
|
case OAK_BUTTON:
|
||||||
|
case SPRUCE_BUTTON:
|
||||||
|
return LoaderButton.WOOD_BUTTON;
|
||||||
|
case STONE_BUTTON:
|
||||||
|
return LoaderButton.STONE_BUTTON;
|
||||||
|
case ACACIA_PRESSURE_PLATE:
|
||||||
|
case BIRCH_PRESSURE_PLATE:
|
||||||
|
case DARK_OAK_PRESSURE_PLATE:
|
||||||
|
case JUNGLE_PRESSURE_PLATE:
|
||||||
|
case OAK_PRESSURE_PLATE:
|
||||||
|
case SPRUCE_PRESSURE_PLATE:
|
||||||
|
case STONE_PRESSURE_PLATE:
|
||||||
|
return LoaderButton.PRESSURE_PLATE;
|
||||||
|
case HEAVY_WEIGHTED_PRESSURE_PLATE:
|
||||||
|
case LIGHT_WEIGHTED_PRESSURE_PLATE:
|
||||||
|
return LoaderButton.WEIGHTED_PRESSURE_PLATE;
|
||||||
|
case TRIPWIRE:
|
||||||
|
return LoaderButton.TRIPWIRE;
|
||||||
|
case NOTE_BLOCK:
|
||||||
|
return LoaderButton.NOTEBLOCK;
|
||||||
|
case DAYLIGHT_DETECTOR:
|
||||||
|
return LoaderButton.DAYLIGHTSENSOR;
|
||||||
|
default:
|
||||||
|
return LoaderButton.INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of the SteamWar software.
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -20,18 +20,21 @@
|
|||||||
package de.steamwar.bausystem.features.loader;
|
package de.steamwar.bausystem.features.loader;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.command.GuardCheckType;
|
||||||
|
import de.steamwar.command.GuardChecker;
|
||||||
|
import de.steamwar.command.GuardResult;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
@Linked
|
@Linked(LinkageType.COMMAND)
|
||||||
public class LoaderCommand extends SWCommand implements Listener {
|
public class LoaderCommand extends SWCommand {
|
||||||
|
|
||||||
public LoaderCommand() {
|
protected LoaderCommand() {
|
||||||
super("loader");
|
super("loader", "autoloader", "al");
|
||||||
|
addDefaultHelpMessage("LOADER_HELP_OTHER");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean loaderNullCheck(Loader loader, Player p) {
|
private boolean loaderNullCheck(Loader loader, Player p) {
|
||||||
@ -39,84 +42,120 @@ public class LoaderCommand extends SWCommand implements Listener {
|
|||||||
BauSystem.MESSAGE.send("LOADER_NO_LOADER", p);
|
BauSystem.MESSAGE.send("LOADER_NO_LOADER", p);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "setup", description = "LOADER_HELP_SETUP")
|
@Register(value = "setup", description = "LOADER_HELP_SETUP")
|
||||||
public void setupLoader(@Validator Player player) {
|
public void setupLoader(@Guard Player p) {
|
||||||
if (Loader.getLoader(player) != null) {
|
if (Loader.getLoader(p) != null) {
|
||||||
BauSystem.MESSAGE.send("LOADER_SETUP_STOP_FIRST", player);
|
Loader.getLoader(p).setup();
|
||||||
return;
|
BauSystem.MESSAGE.send("LOADER_BACK_SETUP", p);
|
||||||
|
} else {
|
||||||
|
Loader.newLoader(p);
|
||||||
|
BauSystem.MESSAGE.send("LOADER_NEW", p);
|
||||||
|
BauSystem.MESSAGE.send("LOADER_HOW_TO_START", p);
|
||||||
}
|
}
|
||||||
Loader.newLoader(player);
|
|
||||||
BauSystem.MESSAGE.send("LOADER_NEW", player);
|
|
||||||
BauSystem.MESSAGE.send("LOADER_HOW_TO_START", player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "start", description = "LOADER_HELP_START")
|
@Register(value = "start", description = "LOADER_HELP_START")
|
||||||
public void startLoader(@Validator Player player) {
|
public void startLoader(@Guard Player p) {
|
||||||
Loader loader = Loader.getLoader(player);
|
Loader loader = Loader.getLoader(p);
|
||||||
if (loaderNullCheck(loader, player)) return;
|
if (loaderNullCheck(loader, p)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
loader.start();
|
loader.start();
|
||||||
BauSystem.MESSAGE.send("LOADER_ACTIVE", player);
|
BauSystem.MESSAGE.send("LOADER_ACTIVE", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "stop", description = "LOADER_HELP_STOP")
|
@Register(value = "stop", description = "LOADER_HELP_STOP")
|
||||||
public void stopLoader(@Validator Player player) {
|
public void stopLoader(@Guard Player p) {
|
||||||
Loader loader = Loader.getLoader(player);
|
Loader loader = Loader.getLoader(p);
|
||||||
if (loaderNullCheck(loader, player)) return;
|
if (loaderNullCheck(loader, p)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
loader.stop();
|
loader.stop();
|
||||||
BauSystem.MESSAGE.send("LOADER_STOP", player);
|
BauSystem.MESSAGE.send("LOADER_STOP", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "pause", description = "LOADER_HELP_PAUSE")
|
@Register(value = "pause", description = "LOADER_HELP_PAUSE")
|
||||||
public void pauseLoader(@Validator Player player) {
|
public void pauseLoader(@Guard Player p) {
|
||||||
Loader loader = Loader.getLoader(player);
|
Loader loader = Loader.getLoader(p);
|
||||||
if (loaderNullCheck(loader, player)) return;
|
if (loaderNullCheck(loader, p)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
loader.pause();
|
loader.pause();
|
||||||
BauSystem.MESSAGE.send("LOADER_PAUSED", player);
|
BauSystem.MESSAGE.send("LOADER_PAUSED", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "gui", description = "LOADER_HELP_GUI")
|
@Register(value = "resume", description = "LOADER_HELP_RESUME")
|
||||||
public void guiLoader(@Validator Player player) {
|
public void resumeLoader(@Guard Player p) {
|
||||||
Loader loader = Loader.getLoader(player);
|
Loader loader = Loader.getLoader(p);
|
||||||
if (loaderNullCheck(loader, player)) return;
|
if (loaderNullCheck(loader, p)) {
|
||||||
loader.gui(Loader.SettingsSorting.ALL);
|
return;
|
||||||
|
}
|
||||||
|
loader.resume();
|
||||||
|
BauSystem.MESSAGE.send("LOADER_RESUME", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "wait", description = "LOADER_HELP_WAIT")
|
@Register(value = "wait", description = "LOADER_HELP_WAIT")
|
||||||
public void shotDelayLoader(@Validator Player p, @Min(intValue = 1) @ErrorMessage("LOADER_SMALL_TIME") int delay) {
|
public void shotDelayLoader(@Guard Player p, int delay) {
|
||||||
Loader loader = Loader.getLoader(p);
|
if (delay < 1) {
|
||||||
if (loaderNullCheck(loader, p)) return;
|
|
||||||
if (loader.setTicksBetweenShots(delay)) {
|
|
||||||
BauSystem.MESSAGE.send("LOADER_NEW_TIME", p, delay);
|
|
||||||
} else {
|
|
||||||
BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p);
|
BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
Loader loader = Loader.getLoader(p);
|
||||||
|
if (loaderNullCheck(loader, p)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BauSystem.MESSAGE.send("LOADER_NEW_TIME", p, delay, loader.getTicksBetweenShots());
|
||||||
|
loader.setTicksBetweenShots(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "speed", description = "LOADER_HELP_SPEED")
|
@Register(value = "speed", description = "LOADER_HELP_SPEED")
|
||||||
public void speedLoader(@Validator Player p, @Min(intValue = 0) @ErrorMessage("LOADER_SMALL_TIME") int delay) {
|
public void speedLoader(@Guard Player p, int delay) {
|
||||||
|
if (delay < 0) {
|
||||||
|
BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Loader loader = Loader.getLoader(p);
|
Loader loader = Loader.getLoader(p);
|
||||||
if (loaderNullCheck(loader, p)) return;
|
if (loaderNullCheck(loader, p)) {
|
||||||
BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay);
|
return;
|
||||||
|
}
|
||||||
|
BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay, loader.getTicksBetweenBlocks());
|
||||||
loader.setTicksBetweenBlocks(delay);
|
loader.setTicksBetweenBlocks(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "single", description = "LOADER_HELP_SINGLE")
|
@Register(value = "undo", description = "LOADER_HELP_UNDO")
|
||||||
public void singleLoader(@Validator Player p) {
|
public void undoLast(@Guard Player p) {
|
||||||
Loader loader = Loader.getLoader(p);
|
Loader loader = Loader.getLoader(p);
|
||||||
if (loaderNullCheck(loader, p)) return;
|
if (loaderNullCheck(loader, p)) {
|
||||||
loader.single();
|
return;
|
||||||
BauSystem.MESSAGE.send("LOADER_SINGLE_CMD", p);
|
}
|
||||||
|
BauSystem.MESSAGE.send("LOADER_UNDO", p);
|
||||||
|
loader.undo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Register(value = "clear", description = "LOADER_HELP_CLEAR")
|
||||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
public void clearLoader(@Guard Player p) {
|
||||||
event.getNewSpectator().forEach(player -> {
|
Loader loader = Loader.getLoader(p);
|
||||||
Loader loader = Loader.getLoader(player);
|
if (loaderNullCheck(loader, p)) {
|
||||||
if (loader == null) return;
|
return;
|
||||||
loader.stop();
|
}
|
||||||
});
|
loader.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ClassGuard(value = Player.class, local = true)
|
||||||
|
public GuardChecker loaderGuard() {
|
||||||
|
return (commandSender, guardCheckType, strings, s) -> {
|
||||||
|
Player player = (Player) commandSender;
|
||||||
|
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||||
|
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
|
||||||
|
BauSystem.MESSAGE.send("LOADER_PERMS", player);
|
||||||
|
}
|
||||||
|
return GuardResult.DENIED;
|
||||||
|
}
|
||||||
|
return GuardResult.ALLOWED;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,231 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.loader;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.SWUtils;
|
|
||||||
import de.steamwar.bausystem.features.loader.elements.LoaderElement;
|
|
||||||
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
|
||||||
import de.steamwar.bausystem.features.loader.elements.impl.*;
|
|
||||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.Action;
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class LoaderRecorder implements Listener {
|
|
||||||
|
|
||||||
private Player player;
|
|
||||||
private List<LoaderElement> loaderElementList;
|
|
||||||
private long lastInteraction = TPSUtils.currentRealTick.get();
|
|
||||||
|
|
||||||
public LoaderRecorder(Player player, List<LoaderElement> loaderElementList) {
|
|
||||||
this.player = player;
|
|
||||||
this.loaderElementList = loaderElementList;
|
|
||||||
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
addWaitTime(true);
|
|
||||||
HandlerList.unregisterAll(this);
|
|
||||||
player = null;
|
|
||||||
blockSet.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addWaitTime(boolean last) {
|
|
||||||
if (loaderElementList.isEmpty()) {
|
|
||||||
lastInteraction = TPSUtils.currentRealTick.get();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (loaderElementList.get(loaderElementList.size() - 1) instanceof LoaderWait) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
long diff = TPSUtils.currentRealTick.get() - lastInteraction;
|
|
||||||
if (last) diff = 120;
|
|
||||||
lastInteraction = TPSUtils.currentRealTick.get();
|
|
||||||
loaderElementList.add(new LoaderWait(diff));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
|
||||||
if (event.getPlayer() != player) return;
|
|
||||||
if (event.getBlock().getType() != Material.TNT) return;
|
|
||||||
|
|
||||||
addWaitTime(false);
|
|
||||||
loaderElementList.add(new LoaderTNT(event.getBlock().getLocation()));
|
|
||||||
message("LOADER_BUTTON_TNT");
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
|
||||||
if (event.getPlayer() != player) return;
|
|
||||||
|
|
||||||
boolean removedOne = false;
|
|
||||||
for (int i = 0; i < loaderElementList.size(); i++) {
|
|
||||||
LoaderElement element = loaderElementList.get(i);
|
|
||||||
if (!(element instanceof LoaderInteractionElement)) continue;
|
|
||||||
LoaderInteractionElement interactionElement = (LoaderInteractionElement) element;
|
|
||||||
if (interactionElement.getLocation().equals(event.getBlock().getLocation())) {
|
|
||||||
loaderElementList.remove(i);
|
|
||||||
if (i > 0) {
|
|
||||||
loaderElementList.remove(i - 1);
|
|
||||||
}
|
|
||||||
removedOne = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removedOne) {
|
|
||||||
if (event.getBlock().getType() != Material.TNT) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("LOADER_MESSAGE_UNINTERACT", player));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
||||||
if (event.getPlayer() != player) return;
|
|
||||||
if (player.isSneaking()) return;
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) return;
|
|
||||||
if (event.getClickedBlock().getType() == Material.OBSERVER) return;
|
|
||||||
if (event.getHand() == EquipmentSlot.OFF_HAND) return;
|
|
||||||
|
|
||||||
addWaitTime(false);
|
|
||||||
Block block = event.getClickedBlock();
|
|
||||||
getLoaderInteractionElement(block, (loaderInteractionElement, s) -> {
|
|
||||||
loaderElementList.add(loaderInteractionElement);
|
|
||||||
message(s);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<Location, Long> blockSet = new HashMap<>();
|
|
||||||
private Map<Location, LoaderMovement> movementSet = new HashMap<>();
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
|
||||||
if (event.getPlayer() != player) return;
|
|
||||||
|
|
||||||
Block fromBlock = event.getFrom().getBlock();
|
|
||||||
Block toBlock = event.getTo().getBlock();
|
|
||||||
calcMovementBlocks(fromBlock, toBlock);
|
|
||||||
|
|
||||||
fromBlock = fromBlock.getRelative(0, 1, 0);
|
|
||||||
toBlock = toBlock.getRelative(0, 1, 0);
|
|
||||||
calcMovementBlocks(fromBlock, toBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calcMovementBlocks(Block fromBlock, Block toBlock) {
|
|
||||||
if (!blockSet.containsKey(toBlock.getLocation())) {
|
|
||||||
Long startTime = blockSet.remove(fromBlock.getLocation());
|
|
||||||
LoaderMovement loaderMovement = movementSet.remove(fromBlock.getLocation());
|
|
||||||
if (loaderMovement != null && startTime != null) {
|
|
||||||
loaderMovement.setInitialTicks(TPSUtils.currentRealTick.get() - startTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
blockSet.put(toBlock.getLocation(), TPSUtils.currentRealTick.get());
|
|
||||||
|
|
||||||
addWaitTime(false);
|
|
||||||
loaderMovement = null;
|
|
||||||
Material type = toBlock.getType();
|
|
||||||
switch (type) {
|
|
||||||
case TRIPWIRE:
|
|
||||||
loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_TRIPWIRE", Material.STRING);
|
|
||||||
message("LOADER_BUTTON_TRIPWIRE");
|
|
||||||
break;
|
|
||||||
case LIGHT_WEIGHTED_PRESSURE_PLATE:
|
|
||||||
case HEAVY_WEIGHTED_PRESSURE_PLATE:
|
|
||||||
loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE", type);
|
|
||||||
message("LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (type.name().endsWith("PRESSURE_PLATE")) {
|
|
||||||
loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_PRESSURE_PLATE", type);
|
|
||||||
message("LOADER_BUTTON_PRESSURE_PLATE");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (loaderMovement != null) {
|
|
||||||
movementSet.put(toBlock.getLocation(), loaderMovement);
|
|
||||||
loaderElementList.add(loaderMovement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void getLoaderInteractionElement(Block block, BiConsumer<LoaderInteractionElement<?>, String> consumer) {
|
|
||||||
Material type = block.getType();
|
|
||||||
switch (type) {
|
|
||||||
case COMPARATOR:
|
|
||||||
consumer.accept(new LoaderComparator(block.getLocation()), "LOADER_BUTTON_COMPARATOR");
|
|
||||||
break;
|
|
||||||
case REPEATER:
|
|
||||||
consumer.accept(new LoaderRepeater(block.getLocation()), "LOADER_BUTTON_REPEATER");
|
|
||||||
break;
|
|
||||||
case NOTE_BLOCK:
|
|
||||||
consumer.accept(new LoaderNoteBlock(block.getLocation()), "LOADER_BUTTON_NOTEBLOCK");
|
|
||||||
break;
|
|
||||||
case LEVER:
|
|
||||||
consumer.accept(new LoaderLever(block.getLocation()), "LOADER_BUTTON_SWITCH");
|
|
||||||
break;
|
|
||||||
case DAYLIGHT_DETECTOR:
|
|
||||||
consumer.accept(new LoaderDaylightDetector(block.getLocation()), "LOADER_BUTTON_DAYLIGHT_DETECTOR");
|
|
||||||
break;
|
|
||||||
case LECTERN:
|
|
||||||
consumer.accept(new LoaderLectern(block.getLocation()), "LOADER_BUTTON_LECTERN");
|
|
||||||
break;
|
|
||||||
case IRON_TRAPDOOR:
|
|
||||||
case IRON_DOOR:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (type.name().endsWith("_TRAPDOOR")) {
|
|
||||||
consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_TRAPDOOR", type), "LOADER_BUTTON_TRAPDOOR");
|
|
||||||
} else if (type.name().endsWith("_DOOR")) {
|
|
||||||
consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_DOOR", type), "LOADER_BUTTON_DOOR");
|
|
||||||
} else if (type.name().endsWith("FENCE_GATE")) {
|
|
||||||
consumer.accept(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_FENCEGATE", type), "LOADER_BUTTON_FENCEGATE");
|
|
||||||
} else if (type.name().endsWith("STONE_BUTTON")) {
|
|
||||||
consumer.accept(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_STONE_BUTTON", type, 20), "LOADER_BUTTON_STONE_BUTTON");
|
|
||||||
} else if (type.name().endsWith("BUTTON")) {
|
|
||||||
consumer.accept(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30), "LOADER_BUTTON_WOOD_BUTTON");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void message(String type) {
|
|
||||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", player, BauSystem.MESSAGE.parse(type, player), loaderElementList.size()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.loader;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class LoaderScoreboardElement implements ScoreboardElement {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ScoreboardGroup getGroup() {
|
|
||||||
return ScoreboardGroup.OTHER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int order() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String get(Region region, Player p) {
|
|
||||||
if(!Permission.BUILD.hasPermission(p)) return null;
|
|
||||||
Loader loader = Loader.getLoader(p);
|
|
||||||
if (loader == null) return null;
|
|
||||||
if (loader.getStage() == Loader.Stage.RUNNING) {
|
|
||||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: §a" + loader.getProgress();
|
|
||||||
} else if (loader.getStage() == Loader.Stage.PAUSE) {
|
|
||||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: §c" + loader.getProgress();
|
|
||||||
} else {
|
|
||||||
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
In neuem Issue referenzieren
Einen Benutzer sperren