-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c14954
commit c4c59a7
Showing
5 changed files
with
242 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/net/glowstone/inventory/GlowBeaconInventory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package net.glowstone.inventory; | ||
|
||
import com.google.common.collect.Sets; | ||
import java.util.Set; | ||
import org.bukkit.Material; | ||
import org.bukkit.block.Beacon; | ||
import org.bukkit.event.inventory.InventoryType; | ||
import org.bukkit.inventory.BeaconInventory; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.potion.PotionEffectType; | ||
|
||
public class GlowBeaconInventory extends GlowInventory implements BeaconInventory { | ||
|
||
private static final Set<Material> ALLOWED_MATERIALS = Sets.newHashSet( | ||
Material.EMERALD, Material.DIAMOND, | ||
Material.GOLD_INGOT, Material.IRON_INGOT | ||
); | ||
private static final int INPUT_SLOT = 0; | ||
|
||
public GlowBeaconInventory(Beacon owner) { | ||
super(owner, InventoryType.BEACON); | ||
|
||
getSlot(INPUT_SLOT).setType(InventoryType.SlotType.CRAFTING); | ||
} | ||
|
||
public void setActiveEffects(int primaryId, int secondaryId) { | ||
if (!ALLOWED_MATERIALS.contains(getItem().getType())) { | ||
return; | ||
} | ||
|
||
PotionEffectType primaryType = PotionEffectType.getById(primaryId); | ||
if (primaryType != null) { | ||
((Beacon) getHolder()).setPrimaryEffect(primaryType); | ||
} | ||
PotionEffectType secondaryType = PotionEffectType.getById(secondaryId); | ||
if (secondaryType != null) { | ||
((Beacon) getHolder()).setSecondaryEffect(secondaryType); | ||
} | ||
|
||
getItem().add(-1); | ||
} | ||
|
||
@Override | ||
public void setItem(ItemStack itemStack) { | ||
setItem(INPUT_SLOT, itemStack); | ||
} | ||
|
||
@Override | ||
public ItemStack getItem() { | ||
return getItem(INPUT_SLOT); | ||
} | ||
|
||
@Override | ||
public boolean itemPlaceAllowed(int slot, ItemStack stack) { | ||
if (slot == INPUT_SLOT) { | ||
return ALLOWED_MATERIALS.contains(stack.getType()); | ||
} | ||
return super.itemPlaceAllowed(slot, stack); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,12 @@ | |
import java.util.logging.Level; | ||
import net.glowstone.GlowServer; | ||
import net.glowstone.inventory.GlowAnvilInventory; | ||
import net.glowstone.inventory.GlowBeaconInventory; | ||
import net.glowstone.net.GlowBufUtils; | ||
import net.glowstone.net.GlowSession; | ||
import net.glowstone.net.message.play.game.PluginMessage; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.inventory.InventoryType; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.BookMeta; | ||
|
@@ -177,6 +179,18 @@ int entity (command block minecart) | |
((GlowAnvilInventory) session.getPlayer().getOpenInventory().getTopInventory()) | ||
.setRenameText(name); | ||
break; | ||
case "MC|Beacon": { | ||
Player player = session.getPlayer(); | ||
|
||
if (player.getOpenInventory() == null || player.getOpenInventory().getType() != InventoryType.BEACON) { | ||
break; | ||
} | ||
|
||
GlowBeaconInventory inventory = (GlowBeaconInventory) player.getOpenInventory().getTopInventory(); | ||
inventory.setActiveEffects(buf.readInt(), buf.readInt()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Shevchik
Contributor
|
||
|
||
break; | ||
} | ||
default: | ||
GlowServer.logger.info(session + " used unknown Minecraft channel: " + channel); | ||
break; | ||
|
Doesn't this allow a maliciously modded client to activate an effect using the wrong item?