Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
9ee675eafb
Commit
54f220c6ed
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.warp;
|
||||
|
||||
import de.steamwar.bausystem.shared.BaseArmorStand_15;
|
||||
import net.minecraft.server.v1_15_R1.ChatComponentText;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class WarpEntity_15 extends BaseArmorStand_15 implements AbstractWarpEntity {
|
||||
|
||||
private String name;
|
||||
|
||||
public WarpEntity_15(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;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.warp;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class WarpListener_15 {
|
||||
|
||||
public static AbstractWarpEntity create(World world, Vector position, String name) {
|
||||
return new WarpEntity_15(world, position, name);
|
||||
}
|
||||
}
|
56
BauSystem_15/src/de/steamwar/bausystem/shared/BaseArmorStand_15.java
Normale Datei
56
BauSystem_15/src/de/steamwar/bausystem/shared/BaseArmorStand_15.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 BaseArmorStand_15 extends EntityArmorStand implements AbstractEntity {
|
||||
|
||||
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
|
||||
|
||||
protected Vector position;
|
||||
|
||||
public BaseArmorStand_15(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);
|
||||
}
|
||||
}
|
@ -20,7 +20,6 @@
|
||||
package de.steamwar.bausystem.features.tracer;
|
||||
|
||||
import de.steamwar.bausystem.shared.AbstractEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface AbstractTraceEntity extends AbstractEntity {
|
||||
@ -28,5 +27,4 @@ public interface AbstractTraceEntity extends AbstractEntity {
|
||||
void display(Player player, boolean exploded);
|
||||
|
||||
boolean hide(Player player, boolean always);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.warp;
|
||||
|
||||
import de.steamwar.bausystem.shared.AbstractEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface AbstractWarpEntity extends AbstractEntity {
|
||||
|
||||
void display(Player player);
|
||||
|
||||
void setName(String name);
|
||||
|
||||
boolean hide(Player player);
|
||||
}
|
@ -28,7 +28,6 @@ import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
// TODO: Rewrite!
|
||||
@Getter
|
||||
public class Warp {
|
||||
|
||||
|
111
BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java
Normale Datei
111
BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java
Normale Datei
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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.warp;
|
||||
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.core.VersionedCallable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Linked(LinkageType.LISTENER)
|
||||
public class WarpListener implements Listener {
|
||||
|
||||
private Map<Player, List<AbstractWarpEntity>> warpsShown = new HashMap<>();
|
||||
private Map<Player, List<Warp>> selectedWarps = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (warpsShown.containsKey(event.getPlayer())) {
|
||||
warpsShown.get(event.getPlayer()).forEach(warp -> {
|
||||
warp.hide(event.getPlayer());
|
||||
});
|
||||
warpsShown.remove(event.getPlayer());
|
||||
}
|
||||
if (event.getPlayer().getInventory().getItemInMainHand().getType() != Material.COMPASS) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectedWarps.remove(event.getPlayer());
|
||||
List<AbstractWarpEntity> warps = warpsShown.getOrDefault(event.getPlayer(), new ArrayList<>());
|
||||
Vector current = event.getPlayer().getLocation().clone().add(event.getPlayer().getLocation().getDirection().multiply(5)).toVector();
|
||||
current.setY(event.getPlayer().getLocation().getY() - 1);
|
||||
Warp.getWarps().forEach(warp -> {
|
||||
Vector vector = warp.getLocation().toVector().subtract(event.getPlayer().getLocation().toVector());
|
||||
if (vector.getX() * vector.getX() + vector.getZ() * vector.getZ() < 25) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector position = event.getPlayer().getLocation().toVector().clone().add(vector.normalize().multiply(5));
|
||||
position.setY(event.getPlayer().getLocation().getY() - 1);
|
||||
|
||||
String name = warp.getName();
|
||||
if (position.distanceSquared(current) < 0.2) {
|
||||
name = "§a§l" + name;
|
||||
selectedWarps.computeIfAbsent(event.getPlayer(), player -> new ArrayList<>()).add(warp);
|
||||
}
|
||||
warps.add(createEntity(event.getPlayer(), position, name));
|
||||
});
|
||||
|
||||
warpsShown.put(event.getPlayer(), warps);
|
||||
warps.forEach(warp -> {
|
||||
warp.display(event.getPlayer());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getPlayer().getInventory().getItemInMainHand().getType() != Material.COMPASS) {
|
||||
return;
|
||||
}
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR) {
|
||||
return;
|
||||
}
|
||||
List<Warp> selected = selectedWarps.getOrDefault(event.getPlayer(), new ArrayList<>());
|
||||
if (selected.size() != 1) {
|
||||
return;
|
||||
}
|
||||
selected.get(0).teleport(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public static AbstractWarpEntity createEntity(Player player, Vector position, String name) {
|
||||
return VersionedCallable.call(new VersionedCallable<>(() -> WarpListener_15.create(player.getWorld(), position, name), 15));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
warpsShown.remove(event.getPlayer());
|
||||
selectedWarps.remove(event.getPlayer());
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren