mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-22 11:35:16 +01:00
Fixed base effect applying
This commit is contained in:
parent
ee211916c6
commit
20c68454f4
@ -55,7 +55,6 @@ public class P extends JavaPlugin {
|
||||
public EntityListener entityListener;
|
||||
public InventoryListener inventoryListener;
|
||||
public WorldListener worldListener;
|
||||
public DrinkListener1_9 drinkListener1_9;
|
||||
|
||||
// Language
|
||||
public String language;
|
||||
@ -96,7 +95,6 @@ public class P extends JavaPlugin {
|
||||
entityListener = new EntityListener();
|
||||
inventoryListener = new InventoryListener();
|
||||
worldListener = new WorldListener();
|
||||
drinkListener1_9 = new DrinkListener1_9();
|
||||
getCommand("Brewery").setExecutor(new CommandListener());
|
||||
|
||||
p.getServer().getPluginManager().registerEvents(blockListener, p);
|
||||
@ -104,9 +102,6 @@ public class P extends JavaPlugin {
|
||||
p.getServer().getPluginManager().registerEvents(entityListener, p);
|
||||
p.getServer().getPluginManager().registerEvents(inventoryListener, p);
|
||||
p.getServer().getPluginManager().registerEvents(worldListener, p);
|
||||
if (use1_9) {
|
||||
p.getServer().getPluginManager().registerEvents(drinkListener1_9, p);
|
||||
}
|
||||
|
||||
// Heartbeat
|
||||
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200);
|
||||
|
@ -1,32 +0,0 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import com.dre.brewery.Brew;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
// Workaround to remove unwanted potion effects
|
||||
public class DrinkListener1_9 implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onPlayerDrink(PlayerItemConsumeEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
if (item.getType() == Material.POTION) {
|
||||
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
||||
Brew brew = Brew.get(meta);
|
||||
if (brew == null) {
|
||||
return;
|
||||
}
|
||||
// Throw away former "base" effect and replace with MUNDANE.
|
||||
meta.setBasePotionData(new PotionData(PotionType.MUNDANE, false, false));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -162,7 +163,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
// player drinks a custom potion
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = event.getItem();
|
||||
@ -171,9 +172,18 @@ public class PlayerListener implements Listener {
|
||||
Brew brew = Brew.get(item);
|
||||
if (brew != null) {
|
||||
BPlayer.drink(brew, player);
|
||||
if (player.getGameMode() != org.bukkit.GameMode.CREATIVE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
brew.remove(item);
|
||||
}
|
||||
if (P.use1_9) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
// replace the potion with an empty potion to avoid effects
|
||||
event.setItem(new ItemStack(Material.POTION));
|
||||
} else {
|
||||
// Dont replace the item when keeping the potion, just cancel the event
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (BPlayer.drainItems.containsKey(item.getType())) {
|
||||
BPlayer bplayer = BPlayer.get(player);
|
||||
|
Loading…
Reference in New Issue
Block a user