Skip to content

Commit

Permalink
v4.3.49
Browse files Browse the repository at this point in the history
  • Loading branch information
ZombieStriker committed Jan 1, 2019
1 parent 0f09a75 commit 617397a
Show file tree
Hide file tree
Showing 16 changed files with 403 additions and 256 deletions.
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 4.3.49
Rewrote entity handling system. If the horse is no longer valid, the system will look through the world again to try and find it.

Version 4.3.48
Added ability to claim foals when claimed horses are breed.
Fixed error for claiming horses.
Fixed issue where player cannot pickup saddle on claimed horse.

Version 4.3.47
Fixed horse location verification
Fixed issue where horses would become unregistered on player quit/chuck despawn.
Expand Down
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ disable_basegame_taming: false
disable_StatsInChat: false
disable_StatsInScoreboard: false

#If claimed horses breed, the offspring will be claimed too.
claimFoalOnBreed: true

horsestats:
default_min_speed: 0.1125
default_max_speed: 0.3375
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mcMMOHorse
main: com.blueskullgames.horserpg.HorseRPG
version: 4.3.47
version: 4.3.49
description: An awesome role-playing plugin for horses.
authors: [GetGoodKid,Zombie_Striker]
website: http://www.blueskullgames.com
Expand Down
117 changes: 78 additions & 39 deletions src/com/blueskullgames/horserpg/HorseRPG.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public class HorseRPG extends JavaPlugin {
public static String BANISH_LOADED_CHUNK = "&a The chunk your horse is in must be loaded before bansishement!";
public static String BANISH_OTHER_NOT_ONLINE = "&a That player does not exist!";

public static String FOALBREED = "&a The foal &e%name%&a has been born.*";

public static BukkitTask saveTask, cooldownTask;
public static ConfigAccessor config;
public static Economy econ;
Expand All @@ -144,6 +146,7 @@ public class HorseRPG extends JavaPlugin {
public static boolean banishondisable = true;
public static boolean banishonquit = true;
public static boolean disableBreeding = false;
public static boolean claimBreeding = true;

public static boolean disableTamedHorses = false;

Expand Down Expand Up @@ -232,7 +235,7 @@ public static RPGHorse getHorseNotSpawned(Player p, String[] args, int offset) {
if (args.length <= offset) {
if (ownedHorses.containsKey(p.getName()) && ownedHorses.get(p.getName()).size() > 0) {
for (RPGHorse h : ownedHorses.get(p.getName())) {
if (!hSpawnedHorses.containsKey(h.horse)) {
if (!hSpawnedHorses.containsKey(h.getHorse())) {
return h;
}
}
Expand Down Expand Up @@ -266,7 +269,7 @@ public static RPGHorse getHorseSpawned(Player p, String[] args, int offset) {
if (args.length <= offset) {
if (ownedHorses.containsKey(p.getName()) && ownedHorses.get(p.getName()).size() > 0) {
for (RPGHorse h : ownedHorses.get(p.getName())) {
if (hSpawnedHorses.containsKey(h.horse)) {
if (hSpawnedHorses.containsKey(h.getHorse())) {
return h;
}
}
Expand All @@ -281,7 +284,7 @@ public static RPGHorse getHorseSpawned(Player p, String[] args, int offset) {

if (ownedHorses.containsKey(p.getName()))
for (RPGHorse h : ownedHorses.get(p.getName()))
if (hSpawnedHorses.containsKey(h.horse))
if (hSpawnedHorses.containsKey(h.getHorse()))
if (h.name.equalsIgnoreCase(hName))
return h;
msg(p, HORSE_DOES_NOT_EXIST.replace("%name%", hName));
Expand Down Expand Up @@ -628,8 +631,20 @@ public static void claimHorse(CommandSender sender) {
}

Entity horse = p.getVehicle();

for (RPGHorse rpg : horses) {
if (rpg.getHorse() != null && !rpg.getHorse().isValid()) {
if (horse.getUniqueId().equals(rpg.getHorse().getUniqueId())) {
HorseRPG.hSpawnedHorses.put(horse, HorseRPG.hSpawnedHorses.remove(rpg.getHorse()));
rpg.getHorse().remove();
rpg.setHorse(horse);
break;
}
}
}

if (hSpawnedHorses.containsKey(horse)) {
if (hSpawnedHorses.get(horse).owner.equals(sender.getName())) {
if (hSpawnedHorses.get(horse).owners_name.equals(sender.getName())) {
msg(p, "&aYou already own this horse!");
} else {
msg(p, "&aThis horse is already owned!");
Expand Down Expand Up @@ -696,7 +711,7 @@ public static void claimHorse(CommandSender sender) {
} catch (Error | Exception e) {
}

h.horse = horse;
h.setHorse(horse);
h.setName(h.name);

pCurrentHorse.put(p.getUniqueId(), h);
Expand Down Expand Up @@ -751,25 +766,25 @@ public static void buyHorse(CommandSender sender, boolean buy) {
}
EconomyResponse er2;
try {
er2 = econ.depositPlayer(Bukkit.getOfflinePlayer(h.owner), h.price);
er2 = econ.depositPlayer(Bukkit.getOfflinePlayer(h.owners_name), h.price);
} catch (Exception e) {
er2 = econ.depositPlayer(h.owner, h.price);
er2 = econ.depositPlayer(h.owners_name, h.price);
}
if (!er2.transactionSuccess()) {
econ.depositPlayer(p.getName(), h.price);
return;
}

for (Player seller : instance.getServer().getOnlinePlayers()) {
if (seller.getName().equalsIgnoreCase(h.owner)) {
if (seller.getName().equalsIgnoreCase(h.owners_name)) {
pCurrentHorse.remove(seller.getUniqueId());
msg(seller, "&b" + h.name + "&a sold to &b" + p.getName() + "&a for &b" + econ.format(h.price));
break;
}
}
h.banish();
msg(p, "&b" + h.name + "&a bought from &b" + h.owner + "&a for &b" + econ.format(h.price));
h.owner = p.getName();
msg(p, "&b" + h.name + "&a bought from &b" + h.owners_name + "&a for &b" + econ.format(h.price));
h.owners_name = p.getName();
offers.remove(p.getUniqueId());
}

Expand Down Expand Up @@ -876,7 +891,7 @@ public static void summonHorse(CommandSender sender, String[] args) {
h = getHorseNotSpawned(p, args, 1);
}
if (h != null) {
if (hSpawnedHorses.containsKey(h.horse)) {
if (hSpawnedHorses.containsKey(h.getHorse())) {
msg(p, "&e" + h.name + "&a has already been summoned.");
return;
}
Expand Down Expand Up @@ -940,24 +955,40 @@ public static void banishHorse(CommandSender sender, String[] args, boolean forc
msg(sender, NO_HORSE_SUMMONED);
return;
}
if (horse.horse == null || !horse.horse.getLocation().getChunk().isLoaded()) {

if (!horse.getHorse().isValid()) {
for (RPGHorse rpg : horses) {
if (rpg.getHorse() != null && !rpg.getHorse().isValid()) {
for (Entity e : rpg.getHorse().getNearbyEntities(60, 30, 60)) {
if (e.getUniqueId().equals(rpg.getHorse().getUniqueId())) {
HorseRPG.hSpawnedHorses.put(e, HorseRPG.hSpawnedHorses.remove(rpg.getHorse()));
rpg.getHorse().remove();
rpg.setHorse(e);
break;
}
}
}
}
}

if (horse.getHorse() == null || !horse.getHorse().getLocation().getChunk().isLoaded()) {
msg(sender, BANISH_LOADED_CHUNK);
return;
}
if (forced) {
if (p.getWorld() == horse.horse.getWorld()) {
if (p.getLocation().distanceSquared(horse.horse.getLocation()) >= 10000) {
horse.horse.teleport(p.getLocation());
if (p.getWorld() == horse.getHorse().getWorld()) {
if (p.getLocation().distanceSquared(horse.getHorse().getLocation()) >= 10000) {
horse.getHorse().teleport(p.getLocation());
}
}
if (((Player) sender).getWorld() == horse.horse.getWorld()) {
if (((Player) sender).getLocation().distanceSquared(horse.horse.getLocation()) >= 10000) {
horse.horse.teleport(((Player) sender).getLocation());
if (((Player) sender).getWorld() == horse.getHorse().getWorld()) {
if (((Player) sender).getLocation().distanceSquared(horse.getHorse().getLocation()) >= 10000) {
horse.getHorse().teleport(((Player) sender).getLocation());
}
}
} else {
if (p.getLocation().distanceSquared(horse.horse.getLocation()) >= 10000) {
horse.horse.teleport(p.getLocation());
if (p.getLocation().distanceSquared(horse.getHorse().getLocation()) >= 10000) {
horse.getHorse().teleport(p.getLocation());
}
}
if (!forced)
Expand All @@ -980,7 +1011,7 @@ public static void banishHorse(CommandSender sender, String[] args, boolean forc
if (pCurrentHorse.get(p.getUniqueId()) == horse) {
pCurrentHorse.remove(p.getUniqueId());
for (RPGHorse others : ownedHorses.get(p.getName())) {
if (hSpawnedHorses.containsKey(others.horse)) {
if (hSpawnedHorses.containsKey(others.getHorse())) {
pCurrentHorse.put(p.getUniqueId(), others);
break;
}
Expand Down Expand Up @@ -1155,8 +1186,8 @@ public static void setHorseSpeed(CommandSender sender, String[] args) {
else {
h.generic_speed = Double.parseDouble(args[2]);
}
if (h.horse != null) {
RPGHorse.attributeUtil.setSpeed(h.horse, h.generic_speed);
if (h.getHorse() != null) {
RPGHorse.attributeUtil.setSpeed(h.getHorse(), h.generic_speed);
}
// "&aHorse %oldname% has been changed to %newname%"
msg(p, ChangeSpeedHorse.replace("%oldname%", h.name).replace("%speed%", "" + h.generic_speed));
Expand Down Expand Up @@ -1193,8 +1224,8 @@ public static void setHorseJump(CommandSender sender, String[] args) {
h.generic_jump = Double.parseDouble(args[2]);
}

if (h.horse != null) {
RPGHorse.attributeUtil.setJumpHeight(h.horse, h.generic_jump);
if (h.getHorse() != null) {
RPGHorse.attributeUtil.setJumpHeight(h.getHorse(), h.generic_jump);
}

// "&aHorse %oldname% has been changed to %newname%"
Expand Down Expand Up @@ -1434,9 +1465,9 @@ public static void deleteHorse(CommandSender sender, String[] args) {
horses.remove(h);
// Test if this removes horses.
h_config.removeHorse(h);
if (hSpawnedHorses.containsKey(h.horse)) {
h.horse.remove();
hSpawnedHorses.remove(h.horse);
if (hSpawnedHorses.containsKey(h.getHorse())) {
h.getHorse().remove();
hSpawnedHorses.remove(h.getHorse());
}

msg(p, "&b" + h.name + "&a won't be bothering you anymore.");
Expand Down Expand Up @@ -1620,6 +1651,8 @@ private void initMessages() {
PAGE_DOES_NOT_EXIST = messages.a("Page_does_not_exist", PAGE_DOES_NOT_EXIST);
PLAYER_ONLY = messages.a("Player_only", PLAYER_ONLY);

FOALBREED = messages.a("Breed_New_Foal", FOALBREED);

NO_WILD_HORSES = messages.a("No_wild_horses", NO_WILD_HORSES);
NO_BREED_HORSES = messages.a("No_breeding_horses", NO_BREED_HORSES);
ALLOW_BREEDING = messages.a("Allow_breeding", ALLOW_BREEDING);
Expand Down Expand Up @@ -1698,6 +1731,9 @@ private void initConfig() {
if (fc.contains("horsestats.default_max_jump"))
RPGHorse.maxJump = fc.getDouble("horsestats.default_max_jump");

if (fc.contains("claimFoalOnBreed"))
HorseRPG.claimBreeding = fc.getBoolean("claimFoalOnBreed");

/*
* if (!h_config.containsGlobalVariable(Keys.G_nobanish.toString())) {
* h_config.setGlobalVar(Keys.G_nobanish.toString(), false); }else {
Expand Down Expand Up @@ -1905,11 +1941,11 @@ public static void saveHorses(CommandSender sender) {
for (TreeSet<RPGHorse> horseSet : ownedHorses.values()) {
for (RPGHorse h : horseSet)
try {
statement.executeUpdate("insert into horses values('" + h.name + "', '" + h.owner + "', '"
+ h.color + "', '" + h.style + "', '" + h.variant + "', " + (h.godmode ? 1 : 0)
+ ", " + h.swiftness.xp + ", " + h.agility.xp + ", " + h.vitality.xp + ", "
+ h.wrath.xp + ", " + (h.isMale ? 0 : 1) + ", " + h.generic_speed + ", "
+ h.generic_jump + ")");
statement.executeUpdate("insert into horses values('" + h.name + "', '" + h.owners_name
+ "', '" + h.color + "', '" + h.style + "', '" + h.variant + "', "
+ (h.godmode ? 1 : 0) + ", " + h.swiftness.xp + ", " + h.agility.xp + ", "
+ h.vitality.xp + ", " + h.wrath.xp + ", " + (h.isMale ? 0 : 1) + ", "
+ h.generic_speed + ", " + h.generic_jump + ")");
} catch (Error | Exception ed4) {
ed4.printStackTrace();
}
Expand Down Expand Up @@ -2159,16 +2195,19 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

@Override
public void onDisable() {
if (banishondisable)
for (Entry<Entity, RPGHorse> horse : hSpawnedHorses.entrySet()) {
horse.getValue().banish();
if (horse.getKey() != null && horse.getKey().isValid()) {
horse.getKey().remove();
}
}

// Force save all spawned horses.
for (RPGHorse h : hSpawnedHorses.values())
h_config.saveHorse(h, false);
h_config.save();

if (banishondisable)
for (Entity horse : new ArrayList<>(hSpawnedHorses.keySet())) {
hSpawnedHorses.remove(horse).banish();
}

HandlerList.unregisterAll(this);
saveHorses(null);
saveTask.cancel();
Expand Down Expand Up @@ -2214,7 +2253,7 @@ public static void showLeaderBoard(CommandSender sender, String[] args) {
int index = 0;
for (RPGHorse h : map.descendingKeySet()) {
String k = ChatColor.GREEN + "#" + index + " " + h.name.substring(0, Math.min(h.name.length(), 16));
String plaeyerName = h.owner.substring(0, Math.min(29 - k.length(), h.owner.length()));
String plaeyerName = h.owners_name.substring(0, Math.min(29 - k.length(), h.owners_name.length()));
k = k + ChatColor.WHITE + " " + plaeyerName;
if (!DisableshowStatsinInScoreboard)
try {
Expand Down

0 comments on commit 617397a

Please sign in to comment.