1.14 support, better error handling #108

Merged
NorbiPeti merged 22 commits from dev into master 2019-10-30 18:43:31 +00:00
10 changed files with 13 additions and 1841 deletions
Showing only changes of commit f1cec2ced1 - Show all commits

10
pom.xml
View file

@ -38,8 +38,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>10</source>
<target>10</target>
<!-- <compilerArgs>
<arg>-processor</arg>
<arg>buttondevteam.buttonproc.ButtonProcessor, lombok.core.AnnotationProcessor</arg>
@ -53,7 +53,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
@ -193,7 +193,7 @@
<dependency>
<groupId>com.discord4j</groupId>
<artifactId>discord4j-core</artifactId>
<version>3.0.8</version>
<version>3.0.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
<dependency>
@ -223,7 +223,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>

View file

@ -79,7 +79,7 @@ public class MCChatListener implements Listener {
final String authorPlayer = "[" + DPUtils.sanitizeStringNoEscape(e.getChannel().DisplayName().get()) + "] " //
+ ("Minecraft".equals(e.getOrigin()) ? "" : "[" + e.getOrigin().substring(0, 1) + "]") //
+ (DPUtils.sanitizeStringNoEscape(ThorpeUtils.getDisplayName(e.getSender())));
+ (DPUtils.sanitizeStringNoEscape(ChromaUtils.getDisplayName(e.getSender())));
val color = e.getChannel().Color().get();
final Consumer<EmbedCreateSpec> embed = ecs -> {
ecs.setDescription(e.getMessage()).setColor(new Color(color.getRed(),

View file

@ -10,7 +10,6 @@ import discord4j.core.object.entity.*;
import discord4j.core.object.util.Snowflake;
import io.netty.util.collection.LongObjectHashMap;
import lombok.RequiredArgsConstructor;
import lombok.experimental.var;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

View file

@ -1,308 +0,0 @@
package buttondevteam.discordplugin.playerfaker;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.DiscordSenderBase;
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.*;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
import java.util.*;
@Getter
@Setter
@SuppressWarnings("deprecated")
public abstract class DiscordEntity extends DiscordSenderBase implements Entity {
protected DiscordEntity(User user, MessageChannel channel, int entityId, UUID uuid, MinecraftChatModule module) {
super(user, channel);
this.entityId = entityId;
uniqueId = uuid;
this.module = module;
}
private HashMap<String, MetadataValue> metadata = new HashMap<String, MetadataValue>();
private Location location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
private Vector velocity;
private final int entityId;
private EntityDamageEvent lastDamageCause;
private final Set<String> scoreboardTags = new HashSet<String>();
private final UUID uniqueId;
private final MinecraftChatModule module;
@Override
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
metadata.put(metadataKey, newMetadataValue);
}
@Override
public List<MetadataValue> getMetadata(String metadataKey) {
return Collections.singletonList(metadata.get(metadataKey)); // Who needs multiple data anyways
}
@Override
public boolean hasMetadata(String metadataKey) {
return metadata.containsKey(metadataKey);
}
@Override
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
metadata.remove(metadataKey);
}
@Override
public Location getLocation(Location loc) {
if (loc != null) {
loc.setWorld(getWorld());
loc.setX(location.getX());
loc.setY(location.getY());
loc.setZ(location.getZ());
loc.setYaw(location.getYaw());
loc.setPitch(location.getPitch());
}
return loc;
}
@Override
public double getHeight() {
return 0;
}
@Override
public double getWidth() {
return 0;
}
@Override
public boolean isOnGround() {
return false;
}
@Override
public World getWorld() {
return location.getWorld();
}
@Override
public boolean teleport(Location location) {
if (module.allowFakePlayerTeleports().get())
this.location = location;
return true;
}
@Override
public boolean teleport(Location location, TeleportCause cause) {
if (module.allowFakePlayerTeleports().get())
this.location = location;
return true;
}
@Override
public boolean teleport(Entity destination) {
if (module.allowFakePlayerTeleports().get())
this.location = destination.getLocation();
return true;
}
@Override
public boolean teleport(Entity destination, TeleportCause cause) {
if (module.allowFakePlayerTeleports().get())
this.location = destination.getLocation();
return true;
}
@Override
public List<Entity> getNearbyEntities(double x, double y, double z) {
return Collections.emptyList();
}
@Override
public int getFireTicks() {
return 0;
}
@Override
public int getMaxFireTicks() {
return 0;
}
@Override
public void setFireTicks(int ticks) {
}
@Override
public void remove() {
}
@Override
public boolean isDead() { // Impossible to kill
return false;
}
@Override
public boolean isValid() {
return true;
}
@Override
public Server getServer() {
return Bukkit.getServer();
}
@Override
public Entity getPassenger() {
return null;
}
@Override
public boolean setPassenger(Entity passenger) {
return false;
}
@Override
public List<Entity> getPassengers() {
return Collections.emptyList();
}
@Override
public boolean addPassenger(Entity passenger) {
return false;
}
@Override
public boolean removePassenger(Entity passenger) { // Don't support passengers
return false;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public boolean eject() {
return false;
}
@Override
public float getFallDistance() {
return 0;
}
@Override
public void setFallDistance(float distance) {
}
@Override
public int getTicksLived() {
return 1;
}
@Override
public void setTicksLived(int value) {
}
@Override
public void playEffect(EntityEffect type) {
}
@Override
public boolean isInsideVehicle() {
return false;
}
@Override
public boolean leaveVehicle() {
return false;
}
@Override
public Entity getVehicle() { // Don't support vehicles
return null;
}
@Override
public void setCustomNameVisible(boolean flag) {
}
@Override
public boolean isCustomNameVisible() {
return true;
}
@Override
public void setGlowing(boolean flag) {
}
@Override
public boolean isGlowing() {
return false;
}
@Override
public void setInvulnerable(boolean flag) {
}
@Override
public boolean isInvulnerable() {
return true;
}
@Override
public boolean isSilent() {
return true;
}
@Override
public void setSilent(boolean flag) {
}
@Override
public boolean hasGravity() {
return false;
}
@Override
public void setGravity(boolean gravity) {
}
@Override
public int getPortalCooldown() {
return 0;
}
@Override
public void setPortalCooldown(int cooldown) {
}
@Override
public boolean addScoreboardTag(String tag) {
return scoreboardTags.add(tag);
}
@Override
public boolean removeScoreboardTag(String tag) {
return scoreboardTags.remove(tag);
}
@Override
public PistonMoveReaction getPistonMoveReaction() {
return PistonMoveReaction.IGNORE;
}
@Override
public Entity.Spigot spigot() {
return new Entity.Spigot();
}
}

View file

@ -1,746 +0,0 @@
package buttondevteam.discordplugin.playerfaker;
import buttondevteam.discordplugin.DPUtils;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
import discord4j.core.object.entity.Member;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Delegate;
import org.bukkit.*;
import org.bukkit.advancement.Advancement;
import org.bukkit.advancement.AdvancementProgress;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.map.MapView;
import org.bukkit.permissions.PermissibleBase;
import org.bukkit.permissions.ServerOperator;
import org.bukkit.plugin.Plugin;
import org.bukkit.scoreboard.Scoreboard;
import java.net.InetSocketAddress;
import java.util.*;
@SuppressWarnings("deprecation")
public class DiscordFakePlayer extends DiscordHumanEntity implements Player {
protected DiscordFakePlayer(User user, MessageChannel channel, int entityId, UUID uuid, String mcname, MinecraftChatModule module) {
super(user, channel, entityId, uuid, module);
origPerm = perm = new PermissibleBase(basePlayer = Bukkit.getOfflinePlayer(uuid));
name = mcname;
}
@Delegate(excludes = ServerOperator.class)
private PermissibleBase origPerm;
private @Getter String name;
private @Getter OfflinePlayer basePlayer;
@Getter
@Setter
private PermissibleBase perm;
public void setOp(boolean value) { //CraftPlayer-compatible implementation
this.origPerm.setOp(value);
this.perm.recalculatePermissions();
}
public boolean isOp() { return this.origPerm.isOp(); }
@Override
public EntityType getType() {
return EntityType.PLAYER;
}
@Override
public String getCustomName() {
return user.getUsername();
}
@Override
public void setCustomName(String name) {
}
@Override
public boolean isConversing() {
return false;
}
@Override
public void acceptConversationInput(String input) {
}
@Override
public boolean beginConversation(Conversation conversation) {
return false;
}
@Override
public void abandonConversation(Conversation conversation) {
}
@Override
public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) {
}
@Override
public boolean isOnline() {
return true;// Let's pretend
}
@Override
public boolean isBanned() {
return false;
}
@Override
public boolean isWhitelisted() {
return true;
}
@Override
public void setWhitelisted(boolean value) {
}
@Override
public Player getPlayer() {
return this;
}
@Override
public long getFirstPlayed() {
return 0;
}
@Override
public long getLastPlayed() {
return 0;
}
@Override
public boolean hasPlayedBefore() {
return false;
}
@Override
public Map<String, Object> serialize() {
return new HashMap<>();
}
@Override
public void sendPluginMessage(Plugin source, String channel, byte[] message) {
}
@Override
public Set<String> getListeningPluginChannels() {
return Collections.emptySet();
}
@Override
public String getDisplayName() {
return DPUtils.ignoreError(user.asMember(DiscordPlugin.mainServer.getId())).blockOptional()
.map(Member::getDisplayName).orElse(name);
}
@Override
public void setDisplayName(String name) {
}
@Override
public String getPlayerListName() {
return getName();
}
@Override
public void setPlayerListName(String name) {
}
@Override
public void setCompassTarget(Location loc) {
}
@Override
public Location getCompassTarget() {
return new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
}
@Override
public InetSocketAddress getAddress() {
return null;
}
@Override
public void sendRawMessage(String message) {
sendMessage(message);
}
@Override
public void kickPlayer(String message) {
}
@Override
public void chat(String msg) {
Bukkit.getPluginManager()
.callEvent(new AsyncPlayerChatEvent(true, this, msg, new HashSet<>(Bukkit.getOnlinePlayers())));
}
@Override
public boolean performCommand(String command) {
return Bukkit.getServer().dispatchCommand(this, command);
}
@Override
public boolean isSneaking() {
return false;
}
@Override
public void setSneaking(boolean sneak) {
}
@Override
public boolean isSprinting() {
return false;
}
@Override
public void setSprinting(boolean sprinting) {
}
@Override
public void saveData() {
}
@Override
public void loadData() {
}
@Override
public void setSleepingIgnored(boolean isSleeping) {
}
@Override
public boolean isSleepingIgnored() {
return false;
}
@Override
public void playNote(Location loc, byte instrument, byte note) {
}
@Override
public void playNote(Location loc, Instrument instrument, Note note) {
}
@Override
public void playSound(Location location, Sound sound, float volume, float pitch) {
}
@Override
public void playSound(Location location, String sound, float volume, float pitch) {
}
@Override
public void playSound(Location location, Sound sound, SoundCategory category, float volume, float pitch) {
}
@Override
public void playSound(Location location, String sound, SoundCategory category, float volume, float pitch) {
}
@Override
public void stopSound(Sound sound) {
}
@Override
public void stopSound(String sound) {
}
@Override
public void stopSound(Sound sound, SoundCategory category) {
}
@Override
public void stopSound(String sound, SoundCategory category) {
}
@Override
public void playEffect(Location loc, Effect effect, int data) {
}
@Override
public <T> void playEffect(Location loc, Effect effect, T data) {
}
@Override
public void sendBlockChange(Location loc, Material material, byte data) {
}
@Override
public boolean sendChunkChange(Location loc, int sx, int sy, int sz, byte[] data) {
return false;
}
@Override
public void sendBlockChange(Location loc, int material, byte data) {
}
@Override
public void sendSignChange(Location loc, String[] lines) throws IllegalArgumentException {
}
@Override
public void sendMap(MapView map) {
}
@Override
public void updateInventory() {
}
@Override
public void awardAchievement(@SuppressWarnings("deprecation") Achievement achievement) {
}
@Override
public void removeAchievement(@SuppressWarnings("deprecation") Achievement achievement) {
}
@Override
public boolean hasAchievement(@SuppressWarnings("deprecation") Achievement achievement) {
return false;
}
@Override
public void incrementStatistic(Statistic statistic) throws IllegalArgumentException {
}
@Override
public void decrementStatistic(Statistic statistic) throws IllegalArgumentException {
}
@Override
public void incrementStatistic(Statistic statistic, int amount) throws IllegalArgumentException {
}
@Override
public void decrementStatistic(Statistic statistic, int amount) throws IllegalArgumentException {
}
@Override
public void setStatistic(Statistic statistic, int newValue) throws IllegalArgumentException {
}
@Override
public int getStatistic(Statistic statistic) throws IllegalArgumentException {
return 0;
}
@Override
public void incrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException {
}
@Override
public void decrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException {
}
@Override
public int getStatistic(Statistic statistic, Material material) throws IllegalArgumentException {
return 0;
}
@Override
public void incrementStatistic(Statistic statistic, Material material, int amount) throws IllegalArgumentException {
}
@Override
public void decrementStatistic(Statistic statistic, Material material, int amount) throws IllegalArgumentException {
}
@Override
public void setStatistic(Statistic statistic, Material material, int newValue) throws IllegalArgumentException {
}
@Override
public void incrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException {
}
@Override
public void decrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException {
}
@Override
public int getStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException {
return 0;
}
@Override
public void incrementStatistic(Statistic statistic, EntityType entityType, int amount)
throws IllegalArgumentException {
}
@Override
public void decrementStatistic(Statistic statistic, EntityType entityType, int amount) {
}
@Override
public void setStatistic(Statistic statistic, EntityType entityType, int newValue) {
}
@Override
public void setPlayerTime(long time, boolean relative) {
}
@Override
public long getPlayerTime() {
return 0;
}
@Override
public long getPlayerTimeOffset() {
return 0;
}
@Override
public boolean isPlayerTimeRelative() {
return false;
}
@Override
public void resetPlayerTime() {
}
@Override
public void setPlayerWeather(WeatherType type) {
}
@Override
public WeatherType getPlayerWeather() {
return null;
}
@Override
public void resetPlayerWeather() {
}
@Override
public void giveExp(int amount) {
}
@Override
public void giveExpLevels(int amount) {
}
@Override
public float getExp() {
return 0;
}
@Override
public void setExp(float exp) {
}
@Override
public int getLevel() {
return 0;
}
@Override
public void setLevel(int level) {
}
@Override
public int getTotalExperience() {
return 0;
}
@Override
public void setTotalExperience(int exp) {
}
@Override
public float getExhaustion() {
return 0;
}
@Override
public void setExhaustion(float value) {
}
@Override
public float getSaturation() {
return 0;
}
@Override
public void setSaturation(float value) {
}
@Override
public int getFoodLevel() {
return 0;
}
@Override
public void setFoodLevel(int value) {
}
@Override
public Location getBedSpawnLocation() {
return null;
}
@Override
public void setBedSpawnLocation(Location location) {
}
@Override
public void setBedSpawnLocation(Location location, boolean force) {
}
@Override
public boolean getAllowFlight() {
return false;
}
@Override
public void setAllowFlight(boolean flight) {
}
@Override
public void hidePlayer(Player player) {
}
@Override
public void hidePlayer(Plugin plugin, Player player) {
}
@Override
public void showPlayer(Player player) {
}
@Override
public void showPlayer(Plugin plugin, Player player) {
}
@Override
public boolean canSee(Player player) { // Nobody can see them
return false;
}
@Override
public boolean isFlying() {
return false;
}
@Override
public void setFlying(boolean value) {
}
@Override
public void setFlySpeed(float value) throws IllegalArgumentException {
}
@Override
public void setWalkSpeed(float value) throws IllegalArgumentException {
}
@Override
public float getFlySpeed() {
return 0;
}
@Override
public float getWalkSpeed() {
return 0;
}
@Override
public void setTexturePack(String url) {
}
@Override
public void setResourcePack(String url) {
}
@Override
public void setResourcePack(String url, byte[] hash) {
}
@Override
public Scoreboard getScoreboard() {
return null;
}
@Override
public void setScoreboard(Scoreboard scoreboard) throws IllegalArgumentException, IllegalStateException {
}
@Override
public boolean isHealthScaled() {
return false;
}
@Override
public void setHealthScaled(boolean scale) {
}
@Override
public void setHealthScale(double scale) throws IllegalArgumentException {
}
@Override
public double getHealthScale() {
return 1;
}
@Override
public Entity getSpectatorTarget() {
return null;
}
@Override
public void setSpectatorTarget(Entity entity) {
}
@Override
public void sendTitle(String title, String subtitle) {
}
@Override
public void sendTitle(String title, String subtitle, int fadeIn, int stay, int fadeOut) {
}
@Override
public void resetTitle() {
}
@Override
public void spawnParticle(Particle particle, Location location, int count) {
}
@Override
public void spawnParticle(Particle particle, double x, double y, double z, int count) {
}
@Override
public <T> void spawnParticle(Particle particle, Location location, int count, T data) {
}
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, T data) {
}
@Override
public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,
double offsetZ) {
}
@Override
public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
double offsetY, double offsetZ) {
}
@Override
public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,
double offsetZ, T data) {
}
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
double offsetY, double offsetZ, T data) {
}
@Override
public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,
double offsetZ, double extra) {
}
@Override
public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
double offsetY, double offsetZ, double extra) {
}
@Override
public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,
double offsetZ, double extra, T data) {
}
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
double offsetY, double offsetZ, double extra, T data) {
}
@Override
public AdvancementProgress getAdvancementProgress(Advancement advancement) { // TODO: Test
return null;
}
@Override
public String getLocale() {
return null;
}
@Override
public Player.Spigot spigot() {
return new Player.Spigot();
}
}

View file

@ -1,168 +0,0 @@
package buttondevteam.discordplugin.playerfaker;
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.*;
import org.bukkit.inventory.InventoryView.Property;
import java.util.UUID;
public abstract class DiscordHumanEntity extends DiscordLivingEntity implements HumanEntity {
protected DiscordHumanEntity(User user, MessageChannel channel, int entityId, UUID uuid, MinecraftChatModule module) {
super(user, channel, entityId, uuid, module);
}
private PlayerInventory inv = new DiscordPlayerInventory(this);
@Override
public PlayerInventory getInventory() {
return inv;
}
private Inventory enderchest = new DiscordInventory(this);
@Override
public Inventory getEnderChest() {
return enderchest;
}
@Override
public MainHand getMainHand() {
return MainHand.RIGHT;
}
@Override
public boolean setWindowProperty(Property prop, int value) {
return false;
}
@Override
public InventoryView getOpenInventory() { // TODO: Test
return null;
}
@Override
public InventoryView openInventory(Inventory inventory) {
return null;
}
@Override
public InventoryView openWorkbench(Location location, boolean force) {
return null;
}
@Override
public InventoryView openEnchanting(Location location, boolean force) {
return null;
}
@Override
public void openInventory(InventoryView inventory) {
}
@Override
public InventoryView openMerchant(Villager trader, boolean force) {
return null;
}
@Override
public InventoryView openMerchant(Merchant merchant, boolean force) {
return null;
}
@Override
public void closeInventory() {
}
@Override
public ItemStack getItemInHand() { // TODO: Test all ItemStack methods
return null;
}
@Override
public void setItemInHand(ItemStack item) {
}
@Override
public ItemStack getItemOnCursor() {
return null;
}
@Override
public void setItemOnCursor(ItemStack item) {
}
@Override
public boolean hasCooldown(Material material) {
return false;
}
@Override
public int getCooldown(Material material) {
return 0;
}
@Override
public void setCooldown(Material material, int ticks) {
}
@Override
public boolean isSleeping() {
return false;
}
@Override
public int getSleepTicks() {
return 0;
}
@Override
public GameMode getGameMode() {
return GameMode.SPECTATOR;
}
@Override
public void setGameMode(GameMode mode) {
}
@Override
public boolean isBlocking() {
return false;
}
@Override
public boolean isHandRaised() {
return false;
}
@Override
public int getExpToLevel() {
return 0;
}
@Override
public Entity getShoulderEntityLeft() {
return null;
}
@Override
public void setShoulderEntityLeft(Entity entity) {
}
@Override
public Entity getShoulderEntityRight() {
return null;
}
@Override
public void setShoulderEntityRight(Entity entity) {
}
}

View file

@ -1,212 +0,0 @@
package buttondevteam.discordplugin.playerfaker;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class DiscordInventory implements Inventory {
public DiscordInventory(DiscordHumanEntity holder) {
this.holder = holder;
}
@Override
public int getSize() {
return 0;
}
@Override
public int getMaxStackSize() {
return 0;
}
@Override
public void setMaxStackSize(int size) {
}
@Override
public String getName() {
return "Player inventory";
}
@Override
public ItemStack getItem(int index) {
return null;
}
@Override
public HashMap<Integer, ItemStack> addItem(ItemStack... items) throws IllegalArgumentException { // Can't add anything
return new HashMap<>(
IntStream.range(0, items.length).boxed().collect(Collectors.toMap(i -> i, i -> items[i])));
}
@Override
public HashMap<Integer, ItemStack> removeItem(ItemStack... items) throws IllegalArgumentException {
return new HashMap<>(
IntStream.range(0, items.length).boxed().collect(Collectors.toMap(i -> i, i -> items[i])));
}
@Override
public ItemStack[] getContents() {
return new ItemStack[0];
}
@Override
public void setContents(ItemStack[] items) throws IllegalArgumentException {
if (items.length > 0)
throw new IllegalArgumentException("This inventory does not support items");
}
@Override
public ItemStack[] getStorageContents() {
return new ItemStack[0];
}
@Override
public void setStorageContents(ItemStack[] items) throws IllegalArgumentException {
if (items.length > 0)
throw new IllegalArgumentException("This inventory does not support items");
}
@Override
public boolean contains(int materialId) {
return false;
}
@Override
public boolean contains(Material material) throws IllegalArgumentException {
return false;
}
@Override
public boolean contains(ItemStack item) {
return false;
}
@Override
public boolean contains(int materialId, int amount) {
return false;
}
@Override
public boolean contains(Material material, int amount) throws IllegalArgumentException {
return false;
}
@Override
public boolean contains(ItemStack item, int amount) {
return false;
}
@Override
public boolean containsAtLeast(ItemStack item, int amount) {
return false;
}
@Override
public HashMap<Integer, ? extends ItemStack> all(int materialId) {
return new HashMap<>();
}
@Override
public HashMap<Integer, ? extends ItemStack> all(Material material) throws IllegalArgumentException {
return new HashMap<>();
}
@Override
public HashMap<Integer, ? extends ItemStack> all(ItemStack item) {
return new HashMap<>();
}
@Override
public int first(int materialId) {
return -1;
}
@Override
public int first(Material material) throws IllegalArgumentException {
return -1;
}
@Override
public int first(ItemStack item) {
return -1;
}
@Override
public int firstEmpty() {
return -1;
}
@Override
public void remove(int materialId) {
}
@Override
public void remove(Material material) throws IllegalArgumentException {
}
@Override
public void remove(ItemStack item) {
}
@Override
public void clear(int index) {
}
@Override
public void clear() {
}
@Override
public List<HumanEntity> getViewers() {
return new ArrayList<>(0);
}
@Override
public String getTitle() {
return "Player inventory";
}
@Override
public InventoryType getType() {
return InventoryType.PLAYER;
}
private ListIterator<ItemStack> iterator = new ArrayList<ItemStack>(0).listIterator();
@Override
public ListIterator<ItemStack> iterator() {
return iterator;
}
@Override
public ListIterator<ItemStack> iterator(int index) {
return iterator;
}
@Override
public Location getLocation() {
return holder.getLocation();
}
@Override
public void setItem(int index, ItemStack item) {
}
private HumanEntity holder;
@Override
public HumanEntity getHolder() {
return holder;
}
}

View file

@ -1,288 +0,0 @@
package buttondevteam.discordplugin.playerfaker;
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import java.util.*;
public abstract class DiscordLivingEntity extends DiscordEntity implements LivingEntity {
protected DiscordLivingEntity(User user, MessageChannel channel, int entityId, UUID uuid, MinecraftChatModule module) {
super(user, channel, entityId, uuid, module);
}
private @Getter EntityEquipment equipment = new DiscordEntityEquipment(this);
@Getter
@Setter
private static class DiscordEntityEquipment implements EntityEquipment {
private float leggingsDropChance;
private ItemStack leggings;
private float itemInOffHandDropChance;
private ItemStack itemInOffHand;
private float itemInMainHandDropChance;
private ItemStack itemInMainHand;
private float itemInHandDropChance;
private ItemStack itemInHand;
private float helmetDropChance;
private ItemStack helmet;
private float chestplateDropChance;
private ItemStack chestplate;
private float bootsDropChance;
private ItemStack boots;
private ItemStack[] armorContents = new ItemStack[0]; // TODO
private final Entity holder;
public DiscordEntityEquipment(Entity holder) {
this.holder = holder;
}
@Override
public void clear() {
armorContents = new ItemStack[0];
}
}
@Override
public AttributeInstance getAttribute(Attribute attribute) { // We don't support any attributes
return null;
}
@Override
public void damage(double amount) {
}
@Override
public void damage(double amount, Entity source) {
}
@Override
public double getHealth() {
return getMaxHealth();
}
@Override
public void setHealth(double health) {
}
@Override
public double getMaxHealth() {
return 100;
}
@Override
public void setMaxHealth(double health) {
}
@Override
public void resetMaxHealth() {
}
@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile) {
return null;
}
@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
return null;
}
@Override
public double getEyeHeight() {
return 0;
}
@Override
public double getEyeHeight(boolean ignoreSneaking) {
return 0;
}
@Override
public Location getEyeLocation() {
return getLocation();
}
@Override
public List<Block> getLineOfSight(Set<Material> transparent, int maxDistance) {
return Arrays.asList();
}
@Override
public Block getTargetBlock(Set<Material> transparent, int maxDistance) {
return null;
}
@Override
public List<Block> getLastTwoTargetBlocks(Set<Material> transparent, int maxDistance) {
return Arrays.asList();
}
@Override
public int getRemainingAir() {
return 100;
}
@Override
public void setRemainingAir(int ticks) {
}
@Override
public int getMaximumAir() {
return 100;
}
@Override
public void setMaximumAir(int ticks) {
}
@Override
public int getMaximumNoDamageTicks() {
return 100;
}
@Override
public void setMaximumNoDamageTicks(int ticks) {
}
@Override
public double getLastDamage() {
return 0;
}
@Override
public void setLastDamage(double damage) {
}
@Override
public int getNoDamageTicks() {
return 100;
}
@Override
public void setNoDamageTicks(int ticks) {
}
@Override
public Player getKiller() {
return null;
}
@Override
public boolean addPotionEffect(PotionEffect effect) {
return false;
}
@Override
public boolean addPotionEffect(PotionEffect effect, boolean force) {
return false;
}
@Override
public boolean addPotionEffects(Collection<PotionEffect> effects) {
return false;
}
@Override
public boolean hasPotionEffect(PotionEffectType type) {
return false;
}
@Override
public PotionEffect getPotionEffect(PotionEffectType type) {
return null;
}
@Override
public void removePotionEffect(PotionEffectType type) {
}
@Override
public Collection<PotionEffect> getActivePotionEffects() {
return Arrays.asList();
}
@Override
public boolean hasLineOfSight(Entity other) {
return false;
}
@Override
public boolean getRemoveWhenFarAway() {
return false;
}
@Override
public void setRemoveWhenFarAway(boolean remove) {
}
@Override
public void setCanPickupItems(boolean pickup) {
}
@Override
public boolean getCanPickupItems() {
return false;
}
@Override
public boolean isLeashed() {
return false;
}
@Override
public Entity getLeashHolder() throws IllegalStateException {
throw new IllegalStateException();
}
@Override
public boolean setLeashHolder(Entity holder) {
return false;
}
@Override
public boolean isGliding() {
return false;
}
@Override
public void setGliding(boolean gliding) {
}
@Override
public void setAI(boolean ai) {
}
@Override
public boolean hasAI() {
return false;
}
@Override
public void setCollidable(boolean collidable) {
}
@Override
public boolean isCollidable() {
return false;
}
}

View file

@ -1,105 +0,0 @@
package buttondevteam.discordplugin.playerfaker;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public class DiscordPlayerInventory extends DiscordInventory implements PlayerInventory {
public DiscordPlayerInventory(DiscordHumanEntity holder) {
super(holder);
}
@Override
public ItemStack[] getArmorContents() {
return new ItemStack[0];
}
@Override
public ItemStack[] getExtraContents() {
return new ItemStack[0];
}
@Override
public ItemStack getHelmet() {
return null;
}
@Override
public ItemStack getChestplate() {
return null;
}
@Override
public ItemStack getLeggings() {
return null;
}
@Override
public ItemStack getBoots() {
return null;
}
@Override
public void setArmorContents(ItemStack[] items) {
}
@Override
public void setExtraContents(ItemStack[] items) {
}
@Override
public void setHelmet(ItemStack helmet) {
}
@Override
public void setChestplate(ItemStack chestplate) {
}
@Override
public void setLeggings(ItemStack leggings) {
}
@Override
public void setBoots(ItemStack boots) {
}
@Override
public ItemStack getItemInMainHand() {
return null;
}
@Override
public void setItemInMainHand(ItemStack item) {
}
@Override
public ItemStack getItemInOffHand() {
return null;
}
@Override
public void setItemInOffHand(ItemStack item) {
}
@Override
public ItemStack getItemInHand() {
return null;
}
@Override
public void setItemInHand(ItemStack stack) {
}
@Override
public int getHeldItemSlot() {
return 0;
}
@Override
public void setHeldItemSlot(int slot) {
}
@Override
public int clear(int id, int data) {
return 0;
}
}

View file

@ -1,8 +1,8 @@
package buttondevteam.discordplugin.playerfaker.perm;
import buttondevteam.core.MainPlugin;
import buttondevteam.discordplugin.DiscordConnectedPlayer;
import buttondevteam.discordplugin.mcchat.MCChatUtils;
import buttondevteam.discordplugin.playerfaker.DiscordFakePlayer;
import buttondevteam.lib.TBMCCoreAPI;
import me.lucko.luckperms.bukkit.LPBukkitBootstrap;
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
@ -87,10 +87,10 @@ public final class LPInjector implements Listener { //Disable login event for Lu
/* Called when the player starts logging into the server.
At this point, the users data should be present and loaded. */
if (!(e.getPlayer() instanceof DiscordFakePlayer))
if (!(e.getPlayer() instanceof DiscordConnectedPlayer))
return; //Normal players must be handled by the plugin
final DiscordFakePlayer player = (DiscordFakePlayer) e.getPlayer();
final DiscordConnectedPlayer player = (DiscordConnectedPlayer) e.getPlayer();
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
plugin.getLogger().info("Processing login for " + player.getUniqueId() + " - " + player.getName());
@ -155,10 +155,10 @@ public final class LPInjector implements Listener { //Disable login event for Lu
// Wait until the last priority to unload, so plugins can still perform permission checks on this event
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent e) {
if (!(e.getPlayer() instanceof DiscordFakePlayer))
if (!(e.getPlayer() instanceof DiscordConnectedPlayer))
return;
final DiscordFakePlayer player = (DiscordFakePlayer) e.getPlayer();
final DiscordConnectedPlayer player = (DiscordConnectedPlayer) e.getPlayer();
connectionListener.handleDisconnect(player.getUniqueId());
@ -183,7 +183,7 @@ public final class LPInjector implements Listener { //Disable login event for Lu
}
//me.lucko.luckperms.bukkit.inject.permissible.PermissibleInjector
private void inject(DiscordFakePlayer player, LPPermissible newPermissible, PermissibleBase oldPermissible) throws IllegalAccessException, InvocationTargetException {
private void inject(DiscordConnectedPlayer player, LPPermissible newPermissible, PermissibleBase oldPermissible) throws IllegalAccessException, InvocationTargetException {
// seems we have already injected into this player.
if (oldPermissible instanceof LPPermissible) {
@ -207,7 +207,7 @@ public final class LPInjector implements Listener { //Disable login event for Lu
player.setPerm(newPermissible);
}
private void uninject(DiscordFakePlayer player, boolean dummy) throws Exception {
private void uninject(DiscordConnectedPlayer player, boolean dummy) throws Exception {
// gets the players current permissible.
PermissibleBase permissible = player.getPerm();