mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-26 12:15:19 +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 EntityListener entityListener;
|
||||||
public InventoryListener inventoryListener;
|
public InventoryListener inventoryListener;
|
||||||
public WorldListener worldListener;
|
public WorldListener worldListener;
|
||||||
public DrinkListener1_9 drinkListener1_9;
|
|
||||||
|
|
||||||
// Language
|
// Language
|
||||||
public String language;
|
public String language;
|
||||||
@ -96,7 +95,6 @@ public class P extends JavaPlugin {
|
|||||||
entityListener = new EntityListener();
|
entityListener = new EntityListener();
|
||||||
inventoryListener = new InventoryListener();
|
inventoryListener = new InventoryListener();
|
||||||
worldListener = new WorldListener();
|
worldListener = new WorldListener();
|
||||||
drinkListener1_9 = new DrinkListener1_9();
|
|
||||||
getCommand("Brewery").setExecutor(new CommandListener());
|
getCommand("Brewery").setExecutor(new CommandListener());
|
||||||
|
|
||||||
p.getServer().getPluginManager().registerEvents(blockListener, p);
|
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(entityListener, p);
|
||||||
p.getServer().getPluginManager().registerEvents(inventoryListener, p);
|
p.getServer().getPluginManager().registerEvents(inventoryListener, p);
|
||||||
p.getServer().getPluginManager().registerEvents(worldListener, p);
|
p.getServer().getPluginManager().registerEvents(worldListener, p);
|
||||||
if (use1_9) {
|
|
||||||
p.getServer().getPluginManager().registerEvents(drinkListener1_9, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Heartbeat
|
// Heartbeat
|
||||||
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200);
|
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;
|
package com.dre.brewery.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -162,7 +163,7 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// player drinks a custom potion
|
// player drinks a custom potion
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
|
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
@ -171,9 +172,18 @@ public class PlayerListener implements Listener {
|
|||||||
Brew brew = Brew.get(item);
|
Brew brew = Brew.get(item);
|
||||||
if (brew != null) {
|
if (brew != null) {
|
||||||
BPlayer.drink(brew, player);
|
BPlayer.drink(brew, player);
|
||||||
if (player.getGameMode() != org.bukkit.GameMode.CREATIVE) {
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
brew.remove(item);
|
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())) {
|
} else if (BPlayer.drainItems.containsKey(item.getType())) {
|
||||||
BPlayer bplayer = BPlayer.get(player);
|
BPlayer bplayer = BPlayer.get(player);
|
||||||
|
Loading…
Reference in New Issue
Block a user