Skip to content

Commit

Permalink
Minor bug fixes and poor support 1.13.2 (#63)
Browse files Browse the repository at this point in the history
* Fix bug with FactionsUUID on 1.12.2
* Fix dismount bug on hight speed
* 1.13.2 support
* Whoops, fixed broken check on entity registered
  • Loading branch information
CKATEPTb authored and Phiwa committed Dec 22, 2019
1 parent c71aef9 commit 515f6e4
Show file tree
Hide file tree
Showing 7 changed files with 674 additions and 20 deletions.
20 changes: 11 additions & 9 deletions src/main/java/eu/phiwa/dragontravel/core/DragonTravel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class DragonTravel extends JavaPlugin {
private CommandHelpTopic help;

private IEntityRegister entityRegister;
private boolean isEntityRegistered;
private PaymentManager paymentManager;
private DragonManager dragonManager;
private FlightEditor flightEditor;
Expand Down Expand Up @@ -105,6 +106,14 @@ public void onLoad() {
commands = new CustomCommandsManager();
final CommandsManagerRegistration cmdRegister = new CommandsManagerRegistration(this, commands);
cmdRegister.register(DragonTravelCommands.DragonTravelParentCommand.class);
instance = this;

nmsHandler = new NMSHandler();
entityRegister = nmsHandler.getEntityRegister();
dragonManager = DragonManager.getDragonManager();
flightEditor = new FlightEditor();

isEntityRegistered = entityRegister.registerEntity();
}

@Override
Expand All @@ -122,15 +131,8 @@ public void onDisable() {

@Override
public void onEnable() {
instance = this;

nmsHandler = new NMSHandler();
entityRegister = nmsHandler.getEntityRegister();
dragonManager = DragonManager.getDragonManager();
flightEditor = new FlightEditor();

if (!entityRegister.registerEntity()) return;

if (!isEntityRegistered)
return;

setupListeners();
setupFileHandlers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@ public void travel() {
double myX = locX;
double myY = locY;
double myZ = locZ;
double maxDiff = DragonTravel.getInstance().getConfigHandler().getSpeed() + 1;

if (finalMove) {
if ((int) locY > (int) toLoc.getY())
if ((int) locY > (int) toLoc.getY() + maxDiff)
myY -= DragonTravel.getInstance().getConfigHandler().getSpeed();
else if ((int) locY < (int) toLoc.getY())
else if ((int) locY < (int) toLoc.getY() - maxDiff)
myY += DragonTravel.getInstance().getConfigHandler().getSpeed();
else {
if (!getEntity().getWorld().getName().equals(toLoc.getWorld().getName())) {
Expand Down Expand Up @@ -251,7 +252,6 @@ else if (midLocB.getZ() > toLoc.getZ())

// For higher travel speeds the accuracy for dismounts needs
// to be decreased to prevent dragons from getting stuck
double maxDiff = DragonTravel.getInstance().getConfigHandler().getSpeed() + 1;
if (Math.abs(myZ - (int) toLoc.getZ()) <= maxDiff
&& Math.abs(myX - (int) toLoc.getX()) <= maxDiff) {
finalMove = true;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/eu/phiwa/dragontravel/nms/v1_12_R1/RyeDragon.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ public void travel() {
double myX = locX;
double myY = locY;
double myZ = locZ;
double maxDiff = DragonTravel.getInstance().getConfigHandler().getSpeed() + 1;

if (finalMove) {
// Go down to destination
if ((int) locY > (int) toLoc.getY())
// Go down to destination
if ((int) locY > (int) toLoc.getY() + maxDiff)
myY -= DragonTravel.getInstance().getConfigHandler().getSpeed();
// Go up to destination
else if ((int) locY < (int) toLoc.getY())
// Go up to destination
else if ((int) locY < (int) toLoc.getY() - maxDiff)
myY += DragonTravel.getInstance().getConfigHandler().getSpeed();
// Reached destination
else {
Expand Down Expand Up @@ -265,7 +266,6 @@ else if (midLocB.getZ() > toLoc.getZ())

// For higher travel speeds the accuracy for dismounts needs
// to be decreased to prevent dragons from getting stuck
double maxDiff = DragonTravel.getInstance().getConfigHandler().getSpeed() + 1;
if (Math.abs(myZ - (int) toLoc.getZ()) <= maxDiff
&& Math.abs(myX - (int) toLoc.getX()) <= maxDiff) {
finalMove = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ public void travel() {
double myX = locX;
double myY = locY;
double myZ = locZ;
double maxDiff = DragonTravel.getInstance().getConfigHandler().getSpeed() + 1;

if (finalMove) {
// Go down to destination
if ((int) locY > (int) toLoc.getY())
if ((int) locY > (int) toLoc.getY() + maxDiff)
myY -= DragonTravel.getInstance().getConfigHandler().getSpeed();
// Go up to destination
else if ((int) locY < (int) toLoc.getY())
else if ((int) locY < (int) toLoc.getY() - maxDiff)
myY += DragonTravel.getInstance().getConfigHandler().getSpeed();
// Reached destination
else {
Expand Down Expand Up @@ -266,7 +267,6 @@ else if (midLocB.getZ() > toLoc.getZ())

// For higher travel speeds the accuracy for dismounts needs
// to be decreased to prevent dragons from getting stuck
double maxDiff = DragonTravel.getInstance().getConfigHandler().getSpeed() + 1;
if (Math.abs(myZ - (int) toLoc.getZ()) <= maxDiff
&& Math.abs(myX - (int) toLoc.getX()) <= maxDiff) {
finalMove = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package eu.phiwa.dragontravel.nms.v1_13_R2;

import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;

import net.minecraft.server.v1_13_R2.EntityTypes;
import net.minecraft.server.v1_13_R2.MinecraftKey;
import net.minecraft.server.v1_13_R2.RegistryMaterials;

@SuppressWarnings("rawtypes")
public class CustomEntityRegistry extends RegistryMaterials {
private final BiMap<MinecraftKey, EntityTypes> entities = HashBiMap.create();
private final BiMap<EntityTypes, MinecraftKey> entityClasses = this.entities.inverse();
private final Map<EntityTypes, Integer> entityIds = Maps.newHashMap();
private final RegistryMaterials<EntityTypes<?>> wrapped;

public CustomEntityRegistry(RegistryMaterials<EntityTypes<?>> original) {
this.wrapped = original;
}

@Override
public int a(Object key) {
if (entityIds.containsKey(key)) {
return entityIds.get(key);
}

return wrapped.a((EntityTypes) key);
}

@Override
public Object a(Random paramRandom) {
return wrapped.a(paramRandom);
}

@Override
public boolean c(MinecraftKey paramK) {
return wrapped.c(paramK);
}

public EntityTypes findType(Class<?> search) {
for (Object type : wrapped) {
if (((EntityTypes) type).c() == search) {
return (EntityTypes) type;
}
}
return null;
}

@Override
public EntityTypes get(MinecraftKey key) {
if (entities.containsKey(key)) {
return entities.get(key);
}

return wrapped.get(key);
}

@Override
public MinecraftKey getKey(Object value) {
if (entityClasses.containsKey(value)) {
return entityClasses.get(value);
}

return wrapped.getKey((EntityTypes) value);
}

public RegistryMaterials<EntityTypes<?>> getWrapped() {
return wrapped;
}

@Override
public Iterator<Object> iterator() {
return (Iterator) wrapped.iterator();
}

@Override
public Set<Object> keySet() {
return (Set) wrapped.keySet();
}

public void put(int entityId, MinecraftKey key, EntityTypes entityClass) {
entities.put(key, entityClass);
entityIds.put(entityClass, entityId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package eu.phiwa.dragontravel.nms.v1_13_R2;

import eu.phiwa.dragontravel.core.DragonTravel;
import eu.phiwa.dragontravel.core.hooks.server.IEntityRegister;
import net.minecraft.server.v1_13_R2.Entity;
import net.minecraft.server.v1_13_R2.EntityTypes;
import net.minecraft.server.v1_13_R2.MinecraftKey;
import org.bukkit.Bukkit;

public class EntityRegister implements IEntityRegister {
private static CustomEntityRegistry ENTITY_REGISTRY;

public void registerEntityClass(Class<?> clazz) {
if (ENTITY_REGISTRY == null)
return;

Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
EntityTypes<?> type = ENTITY_REGISTRY.findType(search);
MinecraftKey key = ENTITY_REGISTRY.getKey(type);
if (key == null)
continue;
int code = ENTITY_REGISTRY.a(type);
ENTITY_REGISTRY.put(code, key, type);
return;
}
throw new IllegalArgumentException("unable to find valid entity superclass for class " + clazz.toString());
}

@Override
public boolean registerEntity() {
try {
registerEntityClass(RyeDragon.class);
return true;
} catch (Exception e) {
Bukkit.getLogger().info("[DragonTravel] [Error] Could not register the RyeDragon-entity!");
e.printStackTrace();
Bukkit.getPluginManager().disablePlugin(DragonTravel.getInstance());
}
return false;
}
}
Loading

0 comments on commit 515f6e4

Please sign in to comment.