aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/ob
diff options
context:
space:
mode:
authorbotn365 <42187820+botn365@users.noreply.github.com>2020-01-08 16:48:18 +0100
committerGitHub <noreply@github.com>2020-01-08 16:48:18 +0100
commita3a9d4a5c2e466db33879176626670f2f07b635a (patch)
tree8176e79d6be425dc28cc3a612416b832a5bed3c5 /src/Java/gtPlusPlus/xmod/ob
parentd7c83c3cd1036668c1f520f144c08de444f675a4 (diff)
parent6bb3c6872c97b36c84f32bf730eee31206728c74 (diff)
downloadGT5-Unofficial-a3a9d4a5c2e466db33879176626670f2f07b635a.tar.gz
GT5-Unofficial-a3a9d4a5c2e466db33879176626670f2f07b635a.tar.bz2
GT5-Unofficial-a3a9d4a5c2e466db33879176626670f2f07b635a.zip
Merge pull request #7 from alkcorp/master
sync
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/ob')
-rw-r--r--src/Java/gtPlusPlus/xmod/ob/GliderHandler.java135
-rw-r--r--src/Java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java38
2 files changed, 173 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/xmod/ob/GliderHandler.java b/src/Java/gtPlusPlus/xmod/ob/GliderHandler.java
new file mode 100644
index 0000000000..7a53572aae
--- /dev/null
+++ b/src/Java/gtPlusPlus/xmod/ob/GliderHandler.java
@@ -0,0 +1,135 @@
+package gtPlusPlus.xmod.ob;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.data.AutoMap;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
+import gtPlusPlus.core.util.minecraft.PlayerUtils;
+import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+import net.minecraftforge.event.entity.player.PlayerInteractEvent;
+import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
+
+public class GliderHandler {
+
+ private static final AutoMap<Integer> mDimensionalBlacklist = new AutoMap<Integer>();
+
+ @SubscribeEvent
+ public void onItemUsageEx(final PlayerInteractEvent event) {
+ if (event != null && event.entityPlayer != null) {
+
+ if (event.action != Action.RIGHT_CLICK_BLOCK && event.action != Action.RIGHT_CLICK_AIR) {
+ Logger.WARNING("[OpenBlocks] Wrong type of PlayerInteractEvent, skipping.");
+ }
+ if (event.entityPlayer.worldObj.isRemote) {
+ return;
+ }
+
+ ItemStack aItem = event.entityPlayer.getItemInUse();
+ if (!ItemUtils.checkForInvalidItems(aItem)) {
+ Logger.WARNING("[OpenBlocks] Item in use was invalid, trying currentlyEquipped.");
+ aItem = event.entityPlayer.getCurrentEquippedItem();
+ }
+ if (!ItemUtils.checkForInvalidItems(aItem)) {
+ Logger.WARNING("[OpenBlocks] Item in use was invalid, trying heldItem.");
+ aItem = event.entityPlayer.getHeldItem();
+ }
+ if (ItemUtils.checkForInvalidItems(aItem)) {
+ Class aItemGliderClass = ReflectionUtils.getClass("openblocks.common.item.ItemHangGlider");
+ if (aItemGliderClass.isInstance(aItem.getItem())) {
+ if (!canPlayerGlideInThisDimension(event.entityPlayer)){
+ event.setCanceled(true);
+ PlayerUtils.messagePlayer(event.entityPlayer, "Glider is blacklisted in this dimension.");
+ Logger.WARNING("[OpenBlocks] "+event.entityPlayer.getCommandSenderName()+" tried to use glider in dimension "+event.entityPlayer.getEntityWorld().provider.dimensionId+".");
+ }
+ else {
+ Logger.WARNING("[OpenBlocks] "+event.entityPlayer.getCommandSenderName()+" used glider in dimension "+event.entityPlayer.getEntityWorld().provider.dimensionId+".");
+ }
+ }
+ else {
+ Logger.WARNING("[OpenBlocks] Item was not a glider.");
+ }
+ }
+ else {
+ Logger.WARNING("[OpenBlocks] Bad Item in player hand.");
+ }
+ }
+ else {
+ Logger.WARNING("[OpenBlocks] Bad event or player.");
+ }
+
+
+ }
+
+ private static final boolean canPlayerGlideInThisDimension(EntityPlayer aPlayer) {
+ World aWorld = aPlayer.worldObj;
+ if (aWorld == null) {
+ return false;
+ }
+ else {
+ if (aWorld.provider == null) {
+ return false;
+ }
+ else {
+ int aDimID = aWorld.provider.dimensionId;
+ for (int i : mDimensionalBlacklist) {
+ if (i == aDimID) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ static final void populateBlacklist() {
+ if (!mDimensionalBlacklist.isEmpty()) {
+ return;
+ }
+ File aBlacklist = gtPlusPlus.core.util.data.FileUtils.getFile("config/GTplusplus/", "GliderBlacklist", "cfg");
+ List<String> lines = new ArrayList<String>();
+ try {
+ lines = org.apache.commons.io.FileUtils.readLines(aBlacklist, "utf-8");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ if (lines.isEmpty()) {
+ FileWriter fw;
+ try {
+ String aInfoTip = "# Add one dimension ID per line. Lines with a # are comments and are ignored.";
+ fw = new FileWriter(aBlacklist);
+ fw.write(aInfoTip);
+ fw.close();
+ lines.add(aInfoTip);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (!lines.isEmpty()) {
+ for (String s : lines) {
+ if (s != null && !s.equals("") && !s.contains("#")) {
+ s = StringUtils.remove(s, " ");
+ s = StringUtils.trim(s);
+ s = StringUtils.remove(s, ",");
+ Integer g = Integer.decode(s);
+ if (g != null) {
+ mDimensionalBlacklist.add(g);
+ Logger.INFO("[OpenBlocks] Added Dimension with ID '"+g+"' to Blacklist for Glider.");
+ }
+ }
+ }
+ }
+ }
+
+
+}
diff --git a/src/Java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java b/src/Java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java
new file mode 100644
index 0000000000..c1b678f5ee
--- /dev/null
+++ b/src/Java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java
@@ -0,0 +1,38 @@
+package gtPlusPlus.xmod.ob;
+
+import static gtPlusPlus.core.creative.AddToCreativeTab.tabMisc;
+
+import gtPlusPlus.core.item.ModItems;
+import gtPlusPlus.core.item.base.BaseItemBurnable;
+import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.lib.LoadedMods;
+import gtPlusPlus.core.recipe.common.CI;
+import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.core.util.minecraft.FluidUtils;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
+import gtPlusPlus.xmod.railcraft.utils.RailcraftUtils;
+import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
+import net.minecraft.item.ItemStack;
+
+public class HANDLER_OpenBlocks {
+
+ public static void preInit() {
+ if (LoadedMods.OpenBlocks) {
+
+ }
+ }
+
+ public static void init() {
+ if (LoadedMods.OpenBlocks) {
+ GliderHandler.populateBlacklist();
+ }
+ }
+
+ public static void postInit() {
+ if (LoadedMods.OpenBlocks) {
+ Utils.registerEvent(new GliderHandler());
+ }
+ }
+
+}