Skip to content

Commit

Permalink
Riptide toggle and more
Browse files Browse the repository at this point in the history
+Allow server owners to interrupt gliding when riptide is used
+Added configurable messages that support colour codes
*Fixed debug parameters
*Fixed removeOnBreak not working when break is caused by rocket damage
  • Loading branch information
NyarukoDev committed Jan 9, 2020
1 parent b65f3ff commit 40eb9c2
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 13 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Each of the changes (with the current exception of firework star rocket damage)
* Configure how much damage players take when using rockets with and without firework stars
* Decide if players should be able to use consumable items when gliding (food, potions etc.)
* Decide if the elytra should disappear when it breaks like normal tools
* Decide if the elytra should be repairable in an anvil or by the mending enchantment
* Decide if the elytra should be repairable in an anvil
* Decide if the elytra should be repairable by the mending enchantment
* Decide if using riptide during gliding should stop the player's flight

## Permissions:
* `elytrabalance.overrides.itemdamage`
Expand All @@ -18,6 +20,7 @@ Each of the changes (with the current exception of firework star rocket damage)
* `elytrabalance.overrides.eat`
* `elytrabalance.overrides.fix`
* `elytrabalance.overrides.mend`
* `elytrabalance.overrides.riptide`

## Configuration:
```
Expand All @@ -30,7 +33,17 @@ Each of the changes (with the current exception of firework star rocket damage)
"Star": "Additional damage dealt to a player when they boost with a rocket that is equipped with a firework star on top of the default 2 and a half hearts.",
"additionalDamagePerStarRocketUse": 0.0,
"canConsumeFoodInFlight": true,
"canRepairElytra": true
"canMendElytra": true
"canRepairElytra": true,
"canMendElytra": true,
"riptideInterruptsGliding": false;
"consumableBlockedMessage": "You can't eat/drink while gliding!",
"showConsumableBlockedMessage": true,
"elytraDestroyedAndRemovedMessage": "Your elytra has shattered into a million pieces!",
"showElytraDestroyedAndRemovedMessage": false,
"repairAttemptBlockedMessage": "You can't fix an elytra with an anvil!",
"showRepairAttemptBlockedMessage": true,
"riptideInterruptMessage": "Riptide has stopped you gliding!",
"showRiptideInterruptMessage": true
}
```
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.nyaruko</groupId>
<artifactId>ElytraBalance</artifactId>
<version>1.2.2</version>
<version>1.3.0</version>
<packaging>jar</packaging>

<name>ElytraBalance</name>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/nyaruko/elytrabalance/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public class Config {
public boolean canConsumeFoodInFlight = true;
public boolean canRepairElytra = true;
public boolean canMendElytra = true;
public boolean riptideInterruptsGliding = false;

public String consumableBlockedMessage = "You can't eat/drink while gliding!";
public boolean showConsumableBlockedMessage = true;
public String elytraDestroyedAndRemovedMessage = "Your elytra has shattered into a million pieces!";
public boolean showElytraDestroyedAndRemovedMessage = false;
public String repairAttemptBlockedMessage = "You can't fix an elytra with an anvil!";
public boolean showRepairAttemptBlockedMessage = true;
public String riptideInterruptMessage = "Riptide has stopped you gliding!";
public boolean showRiptideInterruptMessage = true;

public Config(int configVersion) {
this.configVersion = configVersion;
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/io/nyaruko/elytrabalance/ElytraBalance.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
import java.nio.file.Files;
import java.util.logging.Level;

import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class ElytraBalance extends JavaPlugin {
/**
* Update this whenever the config is altered
*/
private static final int CONFIG_VERSION = 2;
private static final String VERSION = "1.2.2";
private static final int CONFIG_VERSION = 3;
private static final String VERSION = "1.3.0";
private static Config config;

@Override
Expand All @@ -31,9 +33,9 @@ public void onEnable() {
registerEvents();

if(isEnabled()) {
getLogger().log(Level.INFO, "ElytraBalance v{} successfully loaded.", VERSION);
getLogger().log(Level.INFO, "ElytraBalance v{0} successfully loaded.", VERSION);
} else {
getLogger().log(Level.SEVERE, "ElytraBalance v{} failed to load.", VERSION);
getLogger().log(Level.SEVERE, "ElytraBalance v{0} failed to load.", VERSION);
}
}

Expand Down Expand Up @@ -85,7 +87,7 @@ private void saveConfig(File configFile) {
Gson file = new GsonBuilder().setPrettyPrinting().create();
file.toJson(config, writer);
} catch (IOException e) {
getLogger().log(Level.SEVERE, "Failed to save plugin config: {}", e.getMessage());
getLogger().log(Level.SEVERE, "Failed to save plugin config: {0}", e.getMessage());
this.setEnabled(false);
}
}
Expand All @@ -101,6 +103,10 @@ private void registerEvents() {
getServer().getPluginManager().registerEvents(new FixListener(), this);
}

public static void sendConfigMessage(Player player, String configMessage) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configMessage));
}

public static Config getConfigModel() {
return config;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.nyaruko.elytrabalance.listeners;

import io.nyaruko.elytrabalance.ElytraBalance;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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.PlayerItemDamageEvent;
import org.bukkit.event.player.PlayerRiptideEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.FireworkMeta;
Expand Down Expand Up @@ -41,11 +45,23 @@ public void onBoost(PlayerInteractEvent event) {
Damageable m = (Damageable) elytra.getItemMeta();
if(m != null) {
int durability = m.getDamage() + ElytraBalance.getConfigModel().itemDamageOnRocketUse;
durability = Math.min(durability, 431);
durability = Math.min(durability, 432);
m.setDamage(durability);
elytra.setItemMeta((ItemMeta) m);
Bukkit.getServer().getPluginManager().callEvent(new PlayerItemDamageEvent(p, elytra, ElytraBalance.getConfigModel().itemDamageOnRocketUse));
}
}
}
}

@EventHandler
public void onRipTide(PlayerRiptideEvent event) {
final Player player = event.getPlayer();
ItemStack elytra = player.getInventory().getChestplate();
if(elytra != null && elytra.getType() == Material.ELYTRA && player.isGliding() && ElytraBalance.getConfigModel().riptideInterruptsGliding && !player.hasPermission("elytrabalance.overrides.riptide")) {
player.setGliding(false);
if(ElytraBalance.getConfigModel().showRiptideInterruptMessage)
ElytraBalance.sendConfigMessage(player, ElytraBalance.getConfigModel().riptideInterruptMessage);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.nyaruko.elytrabalance.listeners;

import io.nyaruko.elytrabalance.ElytraBalance;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -24,9 +25,11 @@ public void onBreak(PlayerItemDamageEvent event) {

int durability = ((Damageable) im).getDamage();
if(is.getType() == Material.ELYTRA && !p.hasPermission("elytrabalance.overrides.breakremoval") && durability >= 430) {
ItemStack replacement = new ItemStack(Material.AIR);
p.getInventory().setChestplate(replacement);
p.getInventory().setChestplate(new ItemStack(Material.AIR));
event.setCancelled(true);

if(ElytraBalance.getConfigModel().showElytraDestroyedAndRemovedMessage)
ElytraBalance.sendConfigMessage(event.getPlayer(), ElytraBalance.getConfigModel().elytraDestroyedAndRemovedMessage);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.nyaruko.elytrabalance.listeners;

import io.nyaruko.elytrabalance.ElytraBalance;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -15,6 +16,9 @@ public void onEat(PlayerItemConsumeEvent event) {
Player p = event.getPlayer();
if(p.isGliding() && !p.isSwimming() && !p.hasPermission("elytrabalance.overrides.eat")) {
event.setCancelled(true);

if(ElytraBalance.getConfigModel().showConsumableBlockedMessage)
ElytraBalance.sendConfigMessage(event.getPlayer(), ElytraBalance.getConfigModel().consumableBlockedMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public void onFix(PrepareAnvilEvent event) {
!p.hasPermission("elytrabalance.overrides.fix")) {
event.setResult(null);
p.updateInventory();
if(ElytraBalance.getConfigModel().showRepairAttemptBlockedMessage)
ElytraBalance.sendConfigMessage(p, ElytraBalance.getConfigModel().repairAttemptBlockedMessage);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ElytraBalance
version: 1.2.2
version: 1.3.0
authors: [Nyaruko]
load: POSTWORLD
prefix: EB
Expand Down

0 comments on commit 40eb9c2

Please sign in to comment.